ok Tomasz sorry about that.
apologies everyone sorry for the slow reply was moving around all day.
Anthony, here’s my applystop code for the picture above:
#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"
// ******** 1. Basic Settings/SetOption ********
//OptimizerSetEngine("cmae");
SetBacktestMode( backtestRegular );
SetOption("AllowPositionShrinking", False );
//SetOption("AllowSameBarExit", False );
//SetOption("ActivateStopsImmediately", True );
SetOption("MinPosValue", 0 ); // 0 == No limit!
SetOption("PriceBoundChecking", False ); //FALSE == flag errors !
SetOption("PortfolioReportMode", 0 ); //0-Trade list, 1-Detailed Log, 2-Summary, 3-No output
SetOption("ReverseSignalForcesExit", False );
SetOption("UsePrevBarEquityForPosSizing", True ); // Equity - True = Yesterday Equity, False = Today's
SetTradeDelays( 0,0,0,0 ); // ( Buydelay,Selldelay,Shortdelay,Coverdelay )
// Entry Trigger
LongTrig =
Close > 1.00 AND
Close > Ref(Close,-250) AND
MA(Close * Volume,50) > 500000 AND
DayOfWeek() == 5; //Check on Fridays
ExitTrig =
Close < Ref( Close, -250 ) AND
DayOfWeek() == 5;
Short = Cover = 0; //Long Only system
Buy = Ref(LongTrig,-1);
Sell = Ref(ExitTrig,-1);
BuyPrice = Close;
SellPrice = Close;
stopLength = 8.00 * ATR(50);
ApplyStop( stopTypeTrailing, stopModePoint, stopLength, exitatstop = 2, volatile = true );
//ApplyStop( stopTypeLoss, stopModePercent, 10, exitatstop = 0, volatile = true );
Equity( 1, 0); //evaluates the stops, over all quotes.
inTrade = Flip( Buy, Sell ); //True when Buy, False when Sell
SetOption( "EveryBarNullCheck", True); //null bars throws off our stop loss
stopLine = IIf( inTrade, HighestSince(Buy, H-stopLength), Null );
Plot( stopline, "ATR stopLine", colorTeal, styleLine, 0,0,0,0 );
// 2. Posize/Risk
RoundLotSize = 10;
TickSize = 0.01;
//SetOption( "CommissionMode", 0 ); // 0 - Table (Backtester, Settings->General)
SetOption( "CommissionMode", 1 ); // 1 - Percent
OptEq = 1.5 * 1000000;//Optimize( "OptEq", 1500000, 300000, 900000, 25000 );
SetOption("InitialEquity", OptEq );
MaxOpen = 200;
SetOption("MaxOpenPositions", MaxOpen );
possize = 10000;
SetPositionSize( possize, spsValue );