Problems with trading time and stoploss
Forums › ProRealTime English forum › ProOrder support › Problems with trading time and stoploss
- This topic has 9 replies, 4 voices, and was last updated 4 years ago by
SweZerk.
-
-
04/14/2021 at 6:09 PM #167086
Hi, iv been having some problems with trade time, some of my algos trade even when they shouldent.
iv tried these 2 diffrent ways but in some algos they work and some dont
first1234567891011// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 090000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 1730000timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions to enter long positionssecond1Ctime = time >=090000 and time <1730000with the condition on selling and buying aswell.
been stairing at my code for a week now but cant find the problem.
i also have a problem with a stoploss i found on this site, the problem is that it moves upp and down, not a fan of the down part
ptrail123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141//------------------------------------------------------------------------------------------------------------------------------------------------// Trailing Start//------------------------------------------------------------------------------------------------------------------------------------------------ONCE UseCLOSE = 1 //1=use CLOSE, 0=use High/LowsrcH = close //defaults to CLOSEsrcL = close //defaults to CLOSEIF UseCLOSE = 0 THENsrcH = highsrcL = lowENDIFONCE UsePerCentage = 1 //0=use Pips (default), 1=use Percentages//DirectionSwitch = (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) //True when there's been a change in the direction (likely to be due to a Stop & Reverse)//IF Not OnMarket OR DirectionSwitch THEN//// when NOT OnMarket or thare's been a change in direction, reset values to their default settings//StartPerCent = 0.25 //0.25% to start triggering Trailing Stop (when UsePerCentage=1)StepPerCent = 50 //50% (of the 0.25% above) as a Trqiling Step (when UsePerCentage=1) (set to 100 to make StepSize=TrailStart, set to 200 to make it twice TrailStart)//TrailStart = 30 //30 Start trailing profits from this point (when UsePerCentage=0)IF UsePerCentage THENTrailStart = (close / PipSize) * StartPerCent / 100 //use current price (CLOSE) for calculationsENDIFENDIF//BasePerCent = 0.200 //20.0% Profit percentage to keep when setting BerakEven//StepSize = 10 //10 Pip chunks to increase PercentageIF UsePerCentage THENStepSize = TrailStart * StepPerCent / 100ENDIF//PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunkRoundTO = -0.5 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0 defaults PRT behaviourPriceDistance = 7 * pipsize //7 minimun distance from current pricey1 = 0 //reset to 0y2 = 0 //reset to 0ProfitPerCent = BasePerCent //reset to desired default value//PositionCount = 0SellPrice = 0SellPriceX = 0ExitPrice = 9999999ExitPriceX = 9999999//------------------------------------------------------// --- Update Stop Loss after accumulating new positions//------------------------------------------------------//PositionCount = max(PositionCount,abs(CountOfPosition))//// update Stop Loss only when PositionPrice has changed (actually when increased, we don't move it if there's been some positions exited)////IF PositionCount <> PositionCount[1] AND (ExitPrice + SellPrice)<>9999999 THEN //go on only if Trailing Stop had already started trailingIF PositionPrice <> PositionPrice[1] AND (ExitPrice + SellPrice) <> 9999999 THEN //go on only if Trailing Stop had already started trailingIF LongOnMarket THENq1 = PositionPrice + ((srcH - PositionPrice) * ProfitPerCent) //calculate new SLSellPriceX = max(max(SellPriceX,SellPrice),q1)SellPrice = max(max(SellPriceX,SellPrice),PositionPrice + (y1 * pipsize)) //set exit price to whatever grants greater profits, comopared to the previous oneELSIF ShortOnMarket THENr1 = PositionPrice - ((PositionPrice - srcL) * ProfitPerCent) //calculate new SLExitPriceX = min(min(ExitPriceX,ExitPrice),r1)ExitPrice = min(min(ExitPriceX,ExitPrice),PositionPrice - (y2 * pipsize)) //set exit price to whatever grants greater profits, comopared to the previous oneENDIFENDIF// --- Update END//IF LongOnMarket AND srcH > (PositionPrice + (y1 * pipsize)) THEN //LONG positions//// compute the value of the Percentage of profits, if any, to lock in for LONG trades//x1 = (srcH - PositionPrice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN // go ahead only if N+ pipsDiff1 = abs(TrailStart - x1) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCentProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y1 = max(x1 * ProfitPerCent, y1) //y1 = % of max profitENDIFELSIF ShortOnMarket AND srcL < (PositionPrice - (y2 * pipsize)) THEN //SHORT positions//// compute the value of the Percentage of profits, if any, to lock in for SHORT trades//x2 = (PositionPrice - srcL) / pipsize //convert price to pipsIF x2 >= TrailStart THEN // go ahead only if N+ pipsDiff2 = abs(TrailStart - x2) //difference from current profit and TrailStartChunks2 = max(0,round((Diff2 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) //compute new size of ProfitPerCentProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y2 = max(x2 * ProfitPerCent, y2) //y2 = % of max profitENDIFENDIF//------------------------------------------------------------------------------// manage actual Exit, if needed//------------------------------------------------------------------------------IF y1 THEN //Place pending STOP order when y1 > 0 (LONG positions)SellPrice = max(SellPrice,PositionPrice + (y1 * pipsize)) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - SellPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSE////sell AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//SELL AT MarketENDIFENDIFIF y2 THEN //Place pending STOP order when y2 > 0 (SHORT positions)ExitPrice = min(ExitPrice,PositionPrice - (y2 * pipsize)) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - ExitPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSE////ExitShort AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//EXITSHORT AT MarketENDIFENDIFhope anyone can point me in the right direction cus im lost.
04/14/2021 at 6:33 PM #167087some of my algos trade even when they shouldent.
By trade … do you mean open a trade or close a trade?
04/14/2021 at 6:45 PM #16708804/14/2021 at 7:18 PM #167092Try using 173000 instead of 1730000 (1 exceeding 0).
04/14/2021 at 7:22 PM #167093with the condition on selling and buying aswell.
So you can sell only when CTime = 1 / True?
Or do you mean SellShort if CTime = 1 / True?
Use GRAPH for all your Buy conditions.
Or post the full code on here and somebody will spot the problem for you.
04/14/2021 at 7:28 PM #167094Try using 173000 instead of 1730000 (1 exceeding 0).
nice spoting 🙂 i tryed removing one 0 but the problem still remains in the backtest atleast.
04/14/2021 at 7:43 PM #167098with the condition on selling and buying aswell.
So you can sell only when CTime = 1 / True?
Or do you mean SellShort if CTime = 1 / True?
Use GRAPH for all your Buy conditions.
Or post the full code on here and somebody will spot the problem for you.
it looks like this
123456789101112131415161718// Conditions to enter long positionsIF not longonmarket and Ctime and c1 and c2 THENBUY 0.25 CONTRACT AT MARKETelsif longonmarket and Ctime and c1 and c1aand COUNTOFLONGSHARES thenBUY 0.25 CONTRACT AT MARKETSET STOP %LOSS 1ENDIF// Conditions to enter short positionsIF not shortonmarket and Ctime and c3 and c4 THENsellshort 0.25 CONTRACT AT MARKETelsif shortonmarket and Ctime and c3 and c4 and COUNTOFSHORTSHARES thensellshort 0.25 CONTRACT AT MARKETSET STOP %LOSS 1ENDIFdont know what graph is but looking into it now haha 🙂 thx m8
04/14/2021 at 7:46 PM #167099If 9h and 17h30 are the time limits you want, having in mind “opentime” is the time at candle open, and “time” is the time at candle close, you used:
1Ctime = time >=090000 and time <173000but maybe you meant to use:
1Ctime = opentime >=090000 and opentime <173000which if keeping “time” and could also be written as:
1Ctime = time >090000 and time <=173000so that with the swapping of >=/< into >/<= , the candle ending at 9h is not included, and the candle ending at 17h30 is included?
04/14/2021 at 7:48 PM #167100Post the lines where you used your conditions.
Apart from the number of digits, the above code doesn’t tell us more, the extra 0 will let trades open from 9am up to 235900.
As to Ctime (and the other time conditions), it depends on how you use them.
123IF Ctime AND YourLongConditions THENBUY....ENDIFwill work.
04/14/2021 at 7:55 PM #167104 -
AuthorPosts
Find exclusive trading pro-tools on