Hi All,
I am new to coding and trying to code something I do on the us30 it is trading with the trend and get in on a retracement confirmation. Risk reward is roughly 10 to 1 or slightly worse so I martingale losses by 0.1 so when I win the loss is covered with a small increase in contract size when taking out a new position. I’m trying to code to free up time. I have tried using snippets from the site but not getting anywhere, any help would be great. I am having trouble with the martingale resetting after a win also how to only increase position size by 0.1 of 1 contract.
I know my entry on retracement is not great but will come back to it once I have a basic code working. (I will add some other time frame for confirmation also some more vol filters and break even)
Thank you for your help much appreciated,
Leigh
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
once n = 1
noEntryBeforeTime = 140000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 213000
timeEnterAfter = time < noEntryAfterTime
/// Conditions to enter long positions
c1 = (close[1] <= close[2])
c2 = (close[2] <= close[3])
c3 = (close >= close)
indicator1 = Volume
c4 = (indicator1 >= indicator1[1])
indicator2 = Average[20](close)
indicator3 = Average[50](close)*1.00044
c5 = (indicator2 >= indicator3)
IF (c1 AND c2 AND c3 AND c4 AND c5) AND timeEnterBefore AND timeEnterAfter THEN
IF PositionPerf(1) <0 THEN
n = n+1
ELSIF PositionPerf(1) =0 THEN
n = n+1
ELSIF PositionPerf(1) >0 THEN
n = n+1
ENDIF
buy n contracts at market
Endif
Set Stop pLoss 14
Set Target pProfit 120
Try this one:
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
once n = 1
noEntryBeforeTime = 140000
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 213000
timeEnterAfter = time < noEntryAfterTime
/// Conditions to enter long positions
c1 = (close[1] <= close[2])
c2 = (close[2] <= close[3])
c3 = (close >= close)
indicator1 = Volume
c4 = (indicator1 >= indicator1[1])
indicator2 = Average[20](close)
indicator3 = Average[50](close)*1.00044
c5 = (indicator2 >= indicator3)
IF STRATEGYPROFIT - STRATEGYPROFIT[1] > 0 THEN
n = 1
ELSIF STRATEGYPROFIT - STRATEGYPROFIT[1] < 0 THEN
n = n * 1.1
ENDIF
IF (c1 AND c2 AND c3 AND c4 AND c5) AND timeEnterBefore AND timeEnterAfter THEN
buy n contracts at market
Endif
Set Stop pLoss 14
Set Target pProfit 120
graph n
Great, thank you Roberto. Much appreciated !