Hi Guys,
I after the functionality for automatically moving my trade to breakeven after it reaches a certain amount of pips.
Is there a simple way to do this? any help would be greatly appreciated.
Thanks Mathew
Not tested:
If not OnMarket then
NewSL = 0
Endif
If NewSL = 0 and PositionPerf > 0 Then
Pips = close * PositionPerf / pipvalue
If Pips >= 20 Then
NewSL = tradeprice
Endif
Endif
If NewSL > 0 Then
SELL at NewSL STOP
EXITshort at NewSL STOP
Endif
no matter whether you’re Long or Short.
Sorry, line 5 should read:
Pips = tradeprice * PositionPerf / pipvalue
Thanks guys, could you also point me in the direction where to enter the code in the platform?
Thanks but I’m still having some trouble,
Does this look right,
// Conditions to enter long positions
IF NOT LongOnMarket AND YourConditions THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
// Conditions to exit long positions
If LongOnMarket AND YourConditions THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
IF NOT ShortOnMarket AND YourConditions THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
// Conditions to exit short positions
IF ShortOnMarket AND YourConditions THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets : Enter your protection stops and profit targets here
If not OnMarket then
NewSL = 0
Endif
If NewSL = 0 and PositionPerf > 0 Then
Pips = tradeprice * PositionPerf / pipvalue
If Pips >= 20 Then
NewSL = tradeprice
Endif
Endif
If NewSL > 0 Then
SELL at NewSL STOP
EXITshort at NewSL STOP
Endif
For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! << 🙂
Actually my correct code should be written as (after testing it on Dax):
If not OnMarket then
NewSL = 0
Endif
If NewSL = 0 and PositionPerf > 0 Then
Pips = tradeprice * PositionPerf
If Pips >= 20*pipsize Then
NewSL = tradeprice
Endif
Endif
If NewSL > 0 Then
SELL at NewSL STOP
EXITshort at NewSL STOP
Endif
Thanks Roberto,
However, I’m still getting a code invalid response. Is there something I’m missing?
// Conditions to enter long positions
IF NOT LongOnMarket AND YourConditions THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
// Conditions to exit long positions
If LongOnMarket AND YourConditions THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
IF NOT ShortOnMarket AND YourConditions THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
// Conditions to exit short positions
IF ShortOnMarket AND YourConditions THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets : Enter your protection stops and profit targets here
If not OnMarket then
NewSL = 0
Endif
If NewSL = 0 and PositionPerf > 0 Then
Pips = tradeprice * PositionPerf
If Pips >= 20*pipsize Then
NewSL = tradeprice
Endif
Endif
If NewSL > 0 Then
SELL at NewSL STOP
EXITshort at NewSL STOP
Endif
I appreciate your time in helping me.
Topic moved from “ProBuilder support” forum (indicators only) to “ProOrder support” (trading strategies and backtests)
Sorry but what do you mean by “invalid response”?
This code works fine (I tested it on Dax and EurUsd, Daily TF):
DEFPARAM CumulateOrders = false
ONCE MA = 100 //100
ONCE t = 0 //0 = sma
ONCE N = 50 * pipsize //50
IF NOT LongOnMarket AND close crosses over average[MA,t] THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
If Not SHortOnMarket AND close crosses under average[MA,t] THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
If not OnMarket then
NewSL = 0
Endif
If NewSL = 0 and PositionPerf > 0 Then
Pips = (tradeprice * PositionPerf)
If Pips >= N Then
NewSL = tradeprice
Endif
Endif
If NewSL > 0 Then
SELL at NewSL STOP
EXITshort at NewSL STOP
Endif
SET TARGET pPROFIT 700 //700-pip goal
//
GraphOnPrice TradePrice coloured(0,0,255,255) AS "BE TradePrice"
GraphOnPrice TradePrice + N coloured(255,0,0,255) AS "Activation"
GraphOnPrice TradePrice + Pips coloured(0,128,0,255) AS "Temp profit"
graph positionperf
Appending GraphOnPrice and Graph at the end of your code greatly enhances debugging.
thanked this post
Great, thanks for your help guys!
This is really helpful – super grateful!