Stoploss not responding with Time Frames

Forums ProRealTime English forum ProOrder support Stoploss not responding with Time Frames

Viewing 7 posts - 1 through 7 (of 7 total)
  • #126335

    Hi Everyone,

    I have a simple code that I am testing and for some reason it doesn’t do what I expect it to do:

    here is the scenario: it is a classic “When bar crosses moving average do…something”

    BUT  if the market goes against me I want to change the StopLoss to the current bar (for example if I was in a short and the market moved long I want to move the SL to the high of the bar that crossed the moving average and to stop me out if it goes higher). This did not work even when I tried adding a TF and when I checked every second. at one point the SL would be 10 and then it goes to -1 and never stops. so I had to add lines 29-31 and 35-37 (SELL and SELLSHORT )

    Could you help me understand why is the stoploss not activated as I would expect it to?

    P.S Here is anotehr problem I had: I was not able to use crossover/under function effectively as any bar higher than the the MA would trigger the bar Crosses MA so I had to create this lower condition in line 7 (AND lowTimeFrame < MovingAverage)

     

     

    #126338

    The code is not complete to be able to test it, since I can’t see how EntryBuffer is defined, hower:

    • a crossover  is detected with CROSSES OVER which means that the previous CLOSING price was < to previous MA and that the current CLOSING price is > current MA, while you defined it mixing HIGH and CLOSE
    • a crossunder is just the other way round using CROSSES UNDER, instead
    • the Stop Loss is used to make sure your account is not wiped out in case the market goes against you, so why would you need to change it when it DOES go against you? Keep the one you set when your trade was entered and change it only if you want to trail it
    • at line 6 I think (but I could not test it) you should add IF Not OnMarket, not to change values when a trade is open
    • at line 22 you should add ENDIF to match line 6
    • remove lines 32 and 38, as there’s no need to set a stop loss when exiting a trade.

     

    1 user thanked author for this post.
    #126343

    Thanks for the quick relpy,

    I simplified the code before loading it here, sorry that I missed a parameter. for EntryBuffer  I used 5 or 10, but it can be any number.

    I guess I was not clear in my question.

    the code in the 15 time frame should be executed even if the trade is active. so if the trade is active and goes against me I don’t want to wait till it reaches the old SL but I want to reset the SL to a lower level then it was originally (for short trades for example) and if the market continues to go against me then the trade should exit on the new SL and re-enter to the opposite direction (in this case go long)

    the “SET STOP LOSS LongStopAt” is ignored (It seems) which is why I added a hack of exiting.

    Yes Lines 32 and 38 were commented out. but I do want to remove the IF clause 29-31 and 35-37 as they are just a hack since re-setting of the SL did not work for me

     

    I hope it is clearer now

    Thanks again,

     

    #126382

    if the trade is active and goes against me I don’t want to wait till it reaches the old SL but I want to reset the SL to a lower level then it was originally

    that’s exactly what the Stop Loss hasn’t been built for! It was built as a buffer to allow for retracements to happen when you enter a position. If, as soon as the market goes againt you, you move it closer, well… why didn’t you put it there from start?

    Stop Loss should be moved to trail price when it goes IN YOUR FAVOUR, not against!

    That’s what I don’t understand.

     

     

     

     

    1 user thanked author for this post.
    #126460

    OK I get it,

    Yes I mean for it to “trail” but to a specific place.

    I will give an example I went in short and the market went down and now the MA has curved down as well.

    I want to change the SL to be nearer the new MA location. so yes, trailing. but not by using percentage but to a very specific location.

    In reality if the market will THEN go against me the NEW/LOWER SL would be triggered to close the trade and it will switch to a new trade which is a long one.

    Maybe my code is not written well, but that is what I am attempting to do.

    Since it didn’t work I had to exit the trade with a condition as a hack, which I prefer not to do

     

    Thanks again!

    #126461

    from your answer I am assuming the re calling stop loss will not work.

    SET STOP LOSS LongStopAt

    should I be calling ploss instead?

    SET STOP pLOSS LongStopAt (points from entry)?

    would that make a difference?

    #126610

    from your answer I am assuming the re calling stop loss will not work.

    SET STOP LOSS LongStopAt

    should I be calling ploss instead?

    SET STOP pLOSS LongStopAt (points from entry)?

    would that make a difference?

    If you trade DAX, SP or similar instruments there’s no difference, actually the correct form should be used, though. LOSS requires a difference in price (40 pips would be 0.0040 in Forex), pLOSS  requires a difference in pips (40, not 0.0040).

    Try this one (I replaced some variable names to make it easier for me to read):

     

    1 user thanked author for this post.
Viewing 7 posts - 1 through 7 (of 7 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login