0% found this document useful (0 votes)
771 views4 pages

Intraday Trend Reversal Afl

This document defines parameters and functions for an RBO trading system in MetaTrader 4/5. It sets trade delays, round lot size, position size, and other options. It defines parameters for entry buffer percentage, stop loss percentage, target percentage, and entry/exit times. Signals are generated for buy, short, sell and cover positions. Plots show entry and exit signals as well as entry/exit levels.

Uploaded by

Rajendra Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
771 views4 pages

Intraday Trend Reversal Afl

This document defines parameters and functions for an RBO trading system in MetaTrader 4/5. It sets trade delays, round lot size, position size, and other options. It defines parameters for entry buffer percentage, stop loss percentage, target percentage, and entry/exit times. Signals are generated for buy, short, sell and cover positions. Plots show entry and exit signals as well as entry/exit levels.

Uploaded by

Rajendra Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Downloaded From https://www.WiseStockTrader.

com
SetTradeDelays( 1, 1, 1, 1 ); //set trade delays at 1 bar open
RoundLotSize = 40; // Define Round Lot Size of the Trading Instrument
SetPositionSize( 500, spsShares ); // Define Fixed Trading Size
SetOption( "InitialEquity", 200000 );
SetOption( "MinShares", 1 );
SetOption( "MinPosValue", 1 ); // Enable Futures Mode
SetOption( "FuturesMode", True );
SetOption( "AllowPositionShrinking", True );
SetOption( "ActivateStopsImmediately", False );
SetOption( "ReverseSignalForcesExit", False );
SetOption( "AllowSameBarExit", False );
SetOption( "CommissionMode", 2 ); // Fixed Brokerage Commissions (Per Trade)
SetOption( "CommissionAmount", 100 ); // Rs 100/Leg Commisions
SetOption( "InterestRate", 0 );
SetOption( "MarginRequirement", 2 ); //Define Margin Requirement
SetOption( "AccountMargin", 2 ); //Define Account Margin

function ParamOptimize( pname, defaultval, minv, maxv, step )


{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}

_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowArrows | chartShowDates );
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,
Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorCustom11, styleNoTitle | GetPriceStyle() );
_SECTION_END();

//////////////////////// DAY
SEPERATOR /////////////////////////////
//--Define all params
_SECTION_BEGIN( "RBO System Parameters" );
EntryBufferPct = ParamOptimize( "Entry Buffer %", 0, 0, 15, 0.1 );
SLPct = ParamOptimize( "SL %", 3, 0.25, 5, 0.25 );
TargetPct = ParamOptimize( "Target %", 5, 0, 100, 0.25 );
MaxTarget = 100;
TargetPct = IIf( TargetPct == 0, MaxTarget, TargetPct );
_SECTION_END();

_SECTION_BEGIN( "RBO System Signals & Time" );


n = 1; //ParamOptimize("Number of B/S to Generate in a Day",1,1,1,1);
ST = ParamOptimize( "Entry Start Time", 0915, 0915, 1445, 1 );
ET = ParamOptimize( "Entry End Time", 1430, 1010, 1530, 1 );
FTime = ParamOptimize( "Exit for the Day @", 1505, 1445, 1530, 1 );
tn = TimeNum();
TimeOK = tn >= ( ST * 100 ) AND tn <= ( ET * 100 );
FT = tn >= ( FTime * 100 );
_SECTION_END();

_SECTION_BEGIN( "RBO System" );


//--New Day & Time. End Day & Time . End Day & Time is null till end of day 1
NewDay = ( Day() != Ref( Day(), -1 ) ) OR BarIndex() == 0;
printf( "\n NewDay : " + NewDay );
EndDay = ( Day() != Ref( Day(), 1 ) );
printf( "\n EndDay : " + EndDay );
FirstBarTime = ValueWhen( NewDay, TimeNum(), 1 );
EndTime = ValueWhen( EndDay, TimeNum(), 1 );
SquareOffTime = EndTime;

Day1 = TimeFrameGetPrice( "O", inDaily ); // current day open

//Calculate ORB and Sl for 5Min RBO


HighestOfDay = HighestSince( NewDay, H, 1 );
LowestOfDay = LowestSince( NewDay, L, 1 );
ORBH = ValueWhen( NewDay, HighestOfDay , 1 ) * ( 1 + ( EntryBufferPct / 100 ) );
ORBL = ValueWhen( NewDay, LowestOfDay , 1 ) * ( 1 - ( EntryBufferPct / 100 ) );

//--Find Buy, Short, Sell & Cover Signals


BarsSinceNewDay = BarsSince( NewDay );
BuySignal = ( H >= ORBH );
printf( "\nBuySignal : " + BuySignal );
ShortSignal = ( L <= ORBL );
printf( "\nShortSignal : " + ShortSignal );
BarsSinceLastBuySignal = ( BarsSince( Ref( BuySignal, -1 ) ) + 1 );
BarsSinceLastShortSignal = ( BarsSince( Ref( ShortSignal, -1 ) ) + 1 );
BarsSinceLastEntrySignal = Min( BarsSinceLastBuySignal, BarsSinceLastShortSignal );
BothEntrySignalsNull = IsNull( BarsSinceLastBuySignal ) AND
IsNull( BarsSinceLastShortSignal ); //true for start of Day 1
Daych = Day() != Ref( Day(), -1 );

B1 = ( O >= ORBH ) AND( C >= ORBH ) AND TimeOK;


S1 = ( O <= ORBL ) AND( C <= ORBL ) AND TimeOK;

Buy = B1; // AND B2;


Short = S1;// AND S2;

Buy = Buy AND Sum( Buy, BarsSince( newday ) + 1 ) <= N ;


Short = Short AND Sum( Short, BarsSince( newday ) + 1 ) <= N ;

BuyPrice = IIf( Buy, Max( ORBH, O ), Null );


ShortPrice = IIf( Short, Min( ORBL, Open ), Null );

ORBHSL = ValueWhen( BuyPrice, BuyPrice ) * ( 1 - ( SLPct / 100 ) );


ORBLSL = ValueWhen( ShortPrice, ShortPrice ) * ( 1 + ( SLPct / 100 ) );
ORBHTarget = ValueWhen( BuyPrice, BuyPrice ) * ( 1 + ( TargetPct / 100 ) );
ORBLTarget = ValueWhen( ShortPrice, ShortPrice ) * ( 1 - ( TargetPct / 100 ) );

Sell = FT OR L <= ORBHSL OR H >= ORBHTarget OR( ( TimeNum() > SquareOffTime - 1 )


AND( BarsSinceNewDay > BarsSinceLastBuySignal ) );
Cover = FT OR H >= ORBLSL OR L <= ORBLTarget OR( ( TimeNum() > SquareOffTime - 1 )
AND( BarsSinceNewDay > BarsSinceLastShortSignal ) );

Buy = ExRem( Buy, Short OR daych OR Sell );


Short = ExRem( Short, Buy OR daych OR Cover );

SellPrice = IIf( Sell, IIf( H >= ORBHTarget, ORBHTarget, Max( ORBHSL, L ) ),


Null );
CoverPrice = IIf( Cover, IIf( L <= ORBLTarget, ORBLTarget, Min( ORBLSL, H ) ), Null
);

//--Handle if ORB broken both sides on same bar


//--And remove duplicate Short & Cover signals, since ExRem did not work as needed
when Buy & Short on same bar
orbBothSides = IIf( Buy AND Short, 1, 0 );
Buy = IIf( orbBothSides AND C <= O, 0, Buy );
Short = IIf( orbBothSides AND C > O, 0, Short );
Sell = IIf( orbBothSides AND C > O AND( L <= ORBHSL ), 1, Sell );
Sell = IIf( ( BarsSince( Buy ) < ( BarsSince( Ref( Sell, -1 ) ) + 1 ) )
OR( BarsSince( Buy ) AND IsNull( BarsSince( Ref( Sell, -1 ) ) ) ), Sell, 0 );
Cover = IIf( orbBothSides AND C <= O AND( H >= ORBLSL ), 1, Cover );
Cover = IIf( ( BarsSince( Short ) < ( BarsSince( Ref( Cover, -1 ) ) + 1 ) )
OR( BarsSince( Short ) AND IsNull( BarsSince( Ref( Cover, -1 ) ) ) ), Cover, 0 );

dist = 3.5 * ATR( 10 );


dist1 = 2.5 * ATR( 10 );

for( i = 0; i < BarCount; i++ )


{
if( Buy[i] )
{
PlotText( "" + C[ i ], i, C[ i ] - dist[i], colorWhite, colorBlue );
}

if( Short[i] )
{
PlotText( "" + C[ i ], i, C[ i ] + dist1[i], colorRed, colorYellow );
}
}

dist = -2 * ATR( 10 );
dist1 = -5.5 * ATR( 10 );

for( i = 0; i < BarCount; i++ )


{
if( Sell[i] )
{
PlotText( "" + C[ i ], i, C[ i ] - dist[i], colorCustom11, colorBlack );
}

if( Cover[i] )
{
PlotText( "" + C[ i ], i, C[ i ] + dist1[i], colorYellow, colorBlack );
}
}

Plot( ORBH, "", colorBlue, styleDots );


Plot( ORBL, "", colorRed, styleDots );
PlotOHLC( ORBL, ORBH, ORBL, ORBH, "", colorGrey40, styleCloud );

/* Plot Buy and Short Signal Arrows */


PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45
);

PlotShapes( IIf( Cover, shapeSmallUpTriangle, shapeNone ), colorYellow, 0, L,


Offset = -40 );
PlotShapes( IIf( Sell, shapeSmallDownTriangle, shapeNone ), colorWhite, 0, H,
Offset = -40 );
_SECTION_END();

//////////////////////// DAY
SEPERATOR /////////////////////////////
_SECTION_BEGIN( "Day Seperator, EOD, Current Price" );
nday = IIf( Day() != Ref( Day(), -1 ), 1, 0 );
Plot( nday, "", 3, styleHistogram | styleDashed | styleNoLabel | styleOwnScale, 0,
1 );
_SECTION_END();

////////////////////PLOT NAME STRATEGY NAME, PRICE, FULL NAME ETC ON


CHART//////////////////
_SECTION_BEGIN( "Get Strategy Name on Chart" );
x = 1;
y = 1;

GfxGradientRect( 1, 1, 1400, 35, colorGrey50, colorDarkGrey );


GfxSetBkMode( 0 );

GfxSelectFont( "Comic Sans MS", 10, 500, False );


GfxSetTextColor( colorYellow );
GfxTextOut( Interval( 2 ), x + 25, y + 20 );

GfxSelectFont( "Tahoma", 10, 1200, False );


GfxSetTextColor( colorWhite );
GfxTextOut( "RBO With TGT & SL", x + 90, y + 20 );

GfxSelectFont( "Arial", 11, 50, False );


GfxSetTextColor( colorWhite );
GfxTextOut( Date(), x + 325, y + 20 );

GfxSelectFont( "Tahoma", 13, 750, False );


GfxSetTextColor( colorGold );
GfxTextOut( Name(), x + 485, y + 18 );

GfxSelectFont( "Tahoma", 13, 750, False );


GfxSetTextColor( colorLavender );
GfxTextOut( FullName(), x + 675, y + 18 );

GfxSelectFont( "Comic Sans MS", 16, 525, False );


GfxSetTextColor( colorYellow );
GfxTextOut( " " + C, x + 925, y + 10 );

YC = TimeFrameGetPrice( "C", inDaily, -1 );


DD = Prec( C - YC, 2 );
xx = Prec( ( DD / YC ) * 100, 2 );
PercH = C > YC;
PercL = C < YC;

GfxSelectFont( "Comic Sans MS", 10, 525, False );


GfxSetTextColor( colorYellow );
GfxTextOut( "" + DD + " (" + xx + "%)", x + 925, y + 38 );

_SECTION_END();

You might also like