Scale out strategy
Forums › ProRealTime English forum › ProOrder support › Scale out strategy
- This topic has 4 replies, 2 voices, and was last updated 3 years ago by GraHal.
-
-
04/13/2021 at 3:19 PM #166960
Hi guys, first post on this great forum. Just a quick question, I have made a strategy from a few bits of code found on this site. The strategy is ment to buy two contracts at entry conditions and set stoploss at 1.5xATR, then it is ment to sell 1 contract at the first profit target which is 1X ATR and also move the stoploss to breakeven/entry price, then sell the remining contract at exit condition. When running backtest I am having issues with the first contract not selling sometime. Anybody have any ideas. As you can tell by my code I am vey new to this.
Thanks guys.
Cheers.
Scale out123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.//DEFPARAM FLATBEFORE = 180000// Cancel all pending orders and close all positions at the "FLATAFTER" time//DEFPARAM FLATAFTER = 080000ONCE i1a = 60ONCE i1d = 2.5ONCE i1b = 23ONCE i2a = 18ONCE i2b = 40ONCE i4a = 12ONCE i4d = 1.5ONCE i4b = 16ONCE i5a = 7ONCE i5b = 14// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 6// Conditions to enter long positionsindicator1 = Average[i1a](close)+i1d*std[i1b](close)c1 = (close CROSSES OVER indicator1)indicator2 = MoneyFlowIndex[i2a]c2 = (indicator2 > i2b)IF (c1 AND c2) and OML = 0 AND not daysForbiddenEntry THENBUY 2 CONTRACT AT MARKETPP=closeOML=1ENDIFif positionprice <> positionprice[1] thenPP = positionpriceendif// Conditions to enter short positionsindicator4 = Average[i4a](close)-i4d*std[i4b](close)c4 = (close CROSSES OVER indicator4)indicator5 = MoneyFlowIndex[i5a]c5 = (indicator5 < i5b)IF (c4 AND c5) and OMS = 0 AND not daysForbiddenEntry THENSELLSHORT 2 CONTRACT AT MARKETPPS = CLOSEOMS = 1ENDIFif PositionPrice <> PositionPrice[1] thenPPS = PositionPriceendif//////////////////////////////////////////////////////////////////////////////Scale out////////////////////////////////////////////////////////////////////////////resetting variables when no trades are on marketATRP = AverageTrueRange[14](close) //ATR for profitATRS = AverageTrueRange[14](close) * 1.5 //ATR + multiplier for stoplossif not onmarket thenpriceexitShort = 0PriceExitLong = 0ProfitTargetShort = 0ProfitTargetLong = 0EntryPrice = 0CurrentPrice = 0SL = 0endif//SHort scale outif shortonmarket thenSL = ATRS //set stoploss at 1.5x ATREntryPrice = TradePrice(1)CurrentPrice = Close[1]ProfitTargetShort = EntryPrice-ATRPif CurrentPrice <= ProfitTargetShort thenPriceExitShort = CLose - ProfitTargetShortendifendif//Close 1 contract at first profit levelif OMS = 1 and PriceExitShort>0 thenSL = EntryPrice //set stoploss to breakevenEXITSHORT 1 CONTRACT AT MARKETOMS = OMS-1endif//Close 2nd contract when PTL under over priceindicator12, ignored, ignored, ignored = CALL "PRC_PerfectTrendLine 2"[7, 3]c10 = (indicator12 CROSSES UNDER close)if C10 thenEXITSHORT AT MARKETOMS = 0endif//Long scale outif longonmarket thenSL = ATRS //set stoploss at 1.5x ATREntryPrice = TradePrice(1)CurrentPrice = Close[1]ProfitTargetLong = EntryPrice+ATRPif CurrentPrice >= ProfitTargetLong thenPriceExitLong = CLose + ProfitTargetLongendifendif//Close 1 contract at first profit level at 1xATR and set stoploss to brek vevnif OML = 1 and priceexitLong>0 thenSL = EntryPrice //set stoploss to break evenSELL 1 CONTRACT AT MARKETOML = OML -1endif//Close 2nd contract when PTL crosses over priceindicator5, ignored, ignored, ignored = CALL "PRC_PerfectTrendLine 2"[7, 3] //7,3c4 = (indicator5 CROSSES OVER close )IF C4 THENsell at marketOML = 0ENDIFSET STOP LOSS SL//SET TARGET PROFIT AverageTrueRange04/13/2021 at 6:19 PM #166973Anybody have any ideas.
It could be to do with use of EntryPrice = TradePrice(1)?
When 1 lot of a 2 lot position has exited then TradePrice(1) would equal to the exit price of the 1 lot … I think I am correct in saying ?
After the 1 lot has exited, you would need to use EntryPrice = TradePrice(2)?
Best wait until somebody confirms I am correct in my assertion above … before you spend too much time changing your code?
You can use GRAPH TradePrice(1) to check if what I say above is correct? Be sure to let us know please.
04/13/2021 at 10:54 PM #167004Thanks for yor time. I will try this and see how it goes.
04/14/2021 at 3:40 PM #167070Thnaks for the GRAPH tip, makes problem solving alot easier, had a few mistakes in the code. One issue I have is the ATR stoploss and profit updating on every candle. Is there a way of taking the ATR value from the trade entry candle only?
ATRP = AverageTrueRange[14](close) //ATR for inital profit short
ATRS = AverageTrueRange[14](close) * 1.5 //ATR + multiplier for stoploss shortSL = EntryPrice + ATRS //set stoploss at 1.5x ATR short
The above code which I am using now changes the stop loss & profit every candle.
Thanks.
04/14/2021 at 4:29 PM #167072Is there a way of taking the ATR value from the trade entry candle only?
Yes … include the ATR values within the … If Not Longonmarket (and Not Shortonmarket) Endif … statement for entry conditions.
-
AuthorPosts
Find exclusive trading pro-tools on