I’ve tidied the post up – again! The ‘Insert PRT Code Button’ is not difficult to find or use! 🙂
[attachment file=75855]
Please understand I have zero coding knowledge. Someone helped me put the algo together. They can’t help me get the stop to entry once in 25 points profit and adviced that I use this forum.
I don’t know what breakevenflag means or how it works.
breakevenflag is just a variable used in this case as a switch . It is either on (=1) or off (=0). If you have reached your 25 pips then it is switched on and so the code knows now that we have achieved that goal. If we later sell then we switch it off so that the code can once again start looking to see when we have a new trade whether it has hit our desired 25 pips.
Thanks for the explanation. How does it set the stop to entry or zero points?
There was a typo in your last code and you had // an important part of the code. I tested this code and it does what you ask for.
// indicators and parameters
defparam cumulateorders = false
defparam flatbefore = 083000
defparam flatafter =170000
possize = 2
IF TIME = 090000 THEN //include the 0910 candle
Top = highest[6](high) // go back 8 candles
Bottom = lowest[6](low) // go back 8 candles
LongsForDay = 0
MaxPos = 1
ENDIF
IF TradeIndex = BarIndex THEN
LongsForDay = LongsForDay + 1
ENDIF
IF TIME >=090000 AND LongsForDay < MaxPos THEN
BUY possize CONTRACTS AT Top +11 STOP
SELLSHORT possize CONTRACTS AT Bottom -11 stop
ENDIF
set target profit 50
set stop loss 170
IF not onmarket then
breakevenflag = 0
ENDIF
IF longonmarket and (CLOSE-TradePrice) > 25 or shortonmarket and (TradePrice - close) > 25 THEN
breakevenflag = 1
ENDIF
IF breakevenflag = 1 THEN
sellshort possize contracts at positionprice stop
sell possize contracts at positionprice stop
ENDIF
Some explanation:
//If you are not in a trade we make sure the flag is switched off
IF not onmarket then
breakevenflag = 0
ENDIF
//Then we check to see if any long or short positions have reached 25 pips or more and we switch the flag on if they have
IF longonmarket and (CLOSE-TradePrice) > 25 or shortonmarket and (TradePrice - close) > 25 THEN
breakevenflag = 1
ENDIF
//if the flag is now switched on telling us that we have previously hit 25 pips then we send stop orders to the market at each candle opening to
//close any long or short positions at the price the trade was opened at
IF breakevenflag = 1 THEN
sellshort possize contracts at positionprice stop
sell possize contracts at positionprice stop
ENDIF
Correct me if I am wrong, but the breakeven rule is triggered with every candle closing. So if within a candle we have a spike in the desired direction nothing happens until candle close time is here, please confirm.
Yes, you’re right, and if the price retraces to a price lower than your treshold before closing, it eon’t Even trigger breakeven even if in profit.
It can be modified so that it compares HIGH instead of CLOSE to your treshold.
Correct me if I am wrong, but the breakeven rule is triggered with every candle closing. So if within a candle we have a spike in the desired direction nothing happens until candle close time is here, please confirm.
Yes but we can only make decisions at the candle close. If it goes 25 pips in profit and then falls back to 5 pips in loss then we have no chance to catch that get out at break even mid candle. Setting a stop loss at break even after a candle has closed just because at sometime during the candle it went above a 25 pip gain would most probably lock in more losses than break evens. We can only do what we can do at candle close and I think the OP was working on short time frames and on markets where 25 pips in a short amount of time is likely.
Thanks for all the help, I went to prepare the algo for automatic trading and got the following:
The following changes must be applied before sending the code to ProOrder:
Trading systems with orders that partially close a position cannot be sent to ProOrder (ex: sell 3 shares at market). Make sure that no quantity is specified in instructions to close positions (in this case the instruction closes the entire position). Ex: sell at market. Exitshort at 1.5 limit
Please help?
Change the last four lines of code to this:
IF breakevenflag = 1 THEN
sellshort at positionprice stop
sell at positionprice stop
ENDIF
Partial position closure is not allowed in ProOrder trading yet. Rumours are that it should be soon.