//------------------------------------------------------------------------- // Définition des paramètres du code Defparam CumulateOrders = False Defparam Preloadbars = 10000 Defparam FlatBefore = 153000 Defparam FlatAfter = 213000 daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 //daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 //************************************************************************ // Heuristics Algorithm P Start If (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) Then optimizeP = optimizeP + 1 EnDif StartingValueP = 10 ResetPeriodP = 5 //Specify no of days after which to reset optimization IncrementP = 1 MaxIncrementP = 3 //Limit of no of IncrementPs either up or down RepsP = 3 //Number of trades to use for analysis MaxValueP = 12 //Maximum allowed value MinValueP = 9 //Minimum allowed value once DayinitP = day once MonthinitP = month If (month = MonthinitP and day = (DayinitP + ResetPeriodP)) or (month = (MonthinitP + 1) and ((month - DayinitP) + day = ResetPeriodP)) Then R2LimE = StartingValueP WinCountBP = 0 StratAvgBP = 0 BestAP = 0 BestBP = 0 DayinitP = day MonthinitP = month EndIf once P = StartingValueP once PincPosP = 1 //Positive IncrementP Position once NincPosP = 1 //Neative IncrementP Position once optimizeP = 0 ////Initialize Heuristicks Engine Counter (Must be IncrementPed at Position Start or Exit) once ModeP = 1 //Switches between negative and positive IncrementPs //once WinCountBP = P //Initialize Best Win Count //GRAPH WinCountBP coloured (0,0,0) AS "WinCountBP" //once StratAvgBP = PP5P //Initialize Best Avg Strategy Profit //GRAPH StratAvgBP coloured (0,0,0) AS "StratAvgBP" If optimizeP = RepsP Then WinCountAP = 0 //Initialize current Win Count StratAvgAP = 0 //Initialize current Avg Strategy Profit For iP = 1 to RepsP Do If positionperf(iP) > 0 Then WinCountAP = WinCountAP + 1 //IncrementP Current WinCount EndIf StratAvgAP = StratAvgAP + (((PositionPerf(iP)*countofposition[iP]*close)*-1)*-1) Next StratAvgAP = StratAvgAP/RepsP //Calculate Current Avg Strategy Profit //Graph (PositionPerf(1)*countofposition[1]*close)*-1 as "PosPerf1" //Graph (PositionPerf(2)*countofposition[2]*close)*-1 as "PosPerf2" //Graph StratAvgAP*-1 as "StratAvgAP" //once BestAP = P00 //GRAPH BestAP coloured (0,0,0) AS "BestAP" If StratAvgAP >= StratAvgBP Then StratAvgBP = StratAvgAP //Update Best Strategy Profit BestAP = P EndIf //once BestBP = P00 //GRAPH BestBP coloured (0,0,0) AS "BestBP" If WinCountAP >= WinCountBP Then WinCountBP = WinCountAP //Update Best Win Count BestBP = P EndIf If WinCountAP > WinCountBP and StratAvgAP > StratAvgBP Then ModeP = 0 ElsIf WinCountAP < WinCountBP and StratAvgAP < StratAvgBP and ModeP = 1 Then P = P - (IncrementP*NincPosP) NincPosP = NincPosP + 1 ModeP = 2 ElsIf WinCountAP >= WinCountBP or StratAvgAP >= StratAvgBP and ModeP = 1 Then P = P + (IncrementP*PincPosP) PincPosP = PincPosP + 1 ModeP = 1 ElsIf WinCountAP < WinCountBP and StratAvgAP < StratAvgBP and ModeP = 2 Then P = P + (IncrementP*PincPosP) PincPosP = PincPosP + 1 ModeP = 1 ElsIf WinCountAP >= WinCountBP or StratAvgAP >= StratAvgBP and ModeP = 2 Then P = P - (IncrementP*NincPosP) NincPosP = NincPosP + 1 ModeP = 2 EndIf If NincPosP > MaxIncrementP or PincPosP > MaxIncrementP Then If BestAP = BestBP Then P = BestAP Else If RepsP >= 10 Then WeightedScoreP = 10 Else WeightedScoreP = round((RepsP/100)*100) EndIf P = round(((BestAP*(20-WeightedScoreP)) + (BestBP*WeightedScoreP))/20) //Lower RepsP = Less weight assigned to Win% EndIf NincPosP = 1 PincPosP = 1 ElsIf P > MaxValueP Then P = MaxValueP ElsIf P < MinValueP Then P = MinValueP EndIF optimizeP = 0 Endif // Heuristics Algorithm P End //************************************************************************ // Heuristics Algorithm 1 Start If (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) Then optimize = optimize + 1 EnDif StartingValue = 0.54 ResetPeriod = 5 //Specify no of hour after which to reset optimization Increment = 0.005 MaxIncrement = 40 //Limit of no of increments either up or down Reps = 3 //Number of trades to use for analysis MaxValue = 0.6 //Maximum allowed value MinValue = 0.4 //Minimum allowed value once Dayinit = day once Monthinit = month If (month = Monthinit and day = (Dayinit + ResetPeriod)) or (month = (Monthinit + 1) and ((month - Dayinit) + day = ResetPeriod)) Then R2LimE = StartingValue WinCountB = 0 StratAvgB = 0 BestA = 0 BestB = 0 Dayinit = day Monthinit = month EndIf once R2LimE = StartingValue once PIncPos = 1 //Positive Increment Position once NIncPos = 1 //Neative Increment Position once Optimize = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit) once Mode = 1 //Switches between negative and positive increments //once WinCountB = 3 //Initialize Best Win Count //GRAPH WinCountB coloured (0,0,0) AS "WinCountB" //once StratAvgB = 4353 //Initialize Best Avg Strategy Profit //GRAPH StratAvgB coloured (0,0,0) AS "StratAvgB" If Optimize = Reps Then WinCountA = 0 //Initialize current Win Count StratAvgA = 0 //Initialize current Avg Strategy Profit For i = 1 to Reps Do If positionperf(i) > 0 Then WinCountA = WinCountA + 1 //Increment Current WinCount EndIf StratAvgA = StratAvgA + (((PositionPerf(i)*countofposition[i]*close)*-1)*-1) Next StratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy Profit //Graph (PositionPerf(1)*countofposition[1]*close)*-1 as "PosPerf1" //Graph (PositionPerf(2)*countofposition[2]*close)*-1 as "PosPerf2" //Graph StratAvgA*-1 as "StratAvgA" //once BestA = 300 //GRAPH BestA coloured (0,0,0) AS "BestA" If StratAvgA >= StratAvgB Then StratAvgB = StratAvgA //Update Best Strategy Profit BestA = R2LimE EndIf //once BestB = 300 //GRAPH BestB coloured (0,0,0) AS "BestB" If WinCountA >= WinCountB Then WinCountB = WinCountA //Update Best Win Count BestB = R2LimE EndIf If WinCountA > WinCountB and StratAvgA > StratAvgB Then Mode = 0 ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 Then R2LimE = R2LimE - (Increment*NIncPos) NIncPos = NIncPos + 1 Mode = 2 ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 Then R2LimE = R2LimE + (Increment*PIncPos) PIncPos = PIncPos + 1 Mode = 1 ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 Then R2LimE = R2LimE + (Increment*PIncPos) PIncPos = PIncPos + 1 Mode = 1 ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 2 Then R2LimE = R2LimE - (Increment*NIncPos) NIncPos = NIncPos + 1 Mode = 2 EndIf If NIncPos > MaxIncrement or PIncPos > MaxIncrement Then If BestA = BestB Then R2LimE = BestA Else If reps >= 10 Then WeightedScore = 10 Else WeightedScore = round((reps/100)*100) EndIf R2LimE = round(((BestA*(20-WeightedScore)) + (BestB*WeightedScore))/20) //Lower Reps = Less weight assigned to Win% EndIf NIncPos = 1 PIncPos = 1 ElsIf R2LimE > MaxValue Then R2LimE = MaxValue ElsIf R2LimE < MinValue Then R2LimE = MinValue EndIF Optimize = 0 EndIf // Heuristics Algorithm 1 End //************************************************************************ // Heuristics Algorithm 2 Start If (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) Then optimize2 = optimize2 + 1 Endif StartingValue2 = 0.7 ResetPeriod2 = 5 //Specify no of months after which to reset optimization Increment2 = 0.005 MaxIncrement2 = 40 //Limit of no of increments either up or down Reps2 = 3 //Number of trades to use for analysis MaxValue2 = 0.8 //Maximum allowed value MinValue2 = 0.6 //Minimum allowed value once Dayinit2 = day once Monthinit2 = month If (month = Monthinit2 and day = (Dayinit2 + ResetPeriod2)) or (month = (Monthinit2 + 1) and ((month - Dayinit2) + day = ResetPeriod2)) Then R2LimS = StartingValue2 WinCountB2 = 0 StratAvgB2 = 0 BestA2 = 0 BestB2 = 0 Dayinit2 = Hour Monthinit2 = Day EndIf once R2LimS = StartingValue2 once PIncPos2 = 1 //Positive Increment Position once NIncPos2 = 1 //Neative Increment Position once Optimize2 = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit) once Mode2 = 1 //Switches between negative and positive increments //once WinCountB2 = 3 //Initialize Best Win Count //GRAPH WinCountB2 coloured (0,0,0) AS "WinCountB2" //once StratAvgB2 = 4353 //Initialize Best Avg Strategy Profit //GRAPH StratAvgB2 coloured (0,0,0) AS "StratAvgB2" If Optimize2 = Reps2 Then WinCountA2 = 0 //Initialize current Win Count StratAvgA2 = 0 //Initialize current Avg Strategy Profit For i2 = 1 to Reps2 Do If positionperf(i2) > 0 Then WinCountA2 = WinCountA2 + 1 //Increment Current WinCount EndIf StratAvgA2 = StratAvgA2 + (((PositionPerf(i2)*countofposition[i2]*close)*-1)*-1) Next StratAvgA2 = StratAvgA2/Reps2 //Calculate Current Avg Strategy Profit //Graph (PositionPerf(1)*countofposition[1]*close)*-1 as "PosPerf1-2" //Graph (PositionPerf(2)*countofposition[2]*close)*-1 as "PosPerf2-2" //Graph StratAvgA2*-1 as "StratAvgA2" //once BestA2 = 300 //GRAPH BestA2 coloured (0,0,0) AS "BestA2" If StratAvgA2 >= StratAvgB2 Then StratAvgB2 = StratAvgA2 //Update Best Strategy Profit BestA2 = R2LimS EndIf //once BestB2 = 300 //GRAPH BestB2 coloured (0,0,0) AS "BestB2" If WinCountA2 >= WinCountB2 Then WinCountB2 = WinCountA2 //Update Best Win Count BestB2 = R2LimS EndIf If WinCountA2 > WinCountB2 and StratAvgA2 > StratAvgB2 Then Mode2 = 0 ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 1 Then R2LimS = R2LimS - (Increment2*NIncPos2) NIncPos2 = NIncPos2 + 1 Mode2 = 2 ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 1 Then R2LimS = R2LimS + (Increment2*PIncPos2) PIncPos2 = PIncPos2 + 1 Mode2 = 1 ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 2 Then R2LimS = R2LimS + (Increment2*PIncPos2) PIncPos2 = PIncPos2 + 1 Mode2 = 1 ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 2 Then R2LimS = R2LimS - (Increment2*NIncPos2) NIncPos2 = NIncPos2 + 1 Mode2 = 2 EndIf If NIncPos2 > MaxIncrement2 or PIncPos2 > MaxIncrement2 Then If BestA2 = BestB2 Then R2LimS = BestA2 Else If reps2 >= 10 Then WeightedScore2 = 10 Else WeightedScore2 = round((reps2/100)*100) EndIf R2LimS = round(((BestA2*(20-WeightedScore2)) + (BestB2*WeightedScore2))/20) //Lower Reps = Less weight assigned to Win% EndIf NIncPos2 = 1 PIncPos2 = 1 ElsIf R2LimS > MaxValue2 Then R2LimS = MaxValue2 ElsIf R2LimS < MinValue2 Then R2LimS = MinValue2 EndIF Optimize2 = 0 EndIf // Heuristics Algorithm 2 End //************************************************************************ // Heuristics Algorithm 3 Start If (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) Then optimize3 = optimize3 + 1 EnDif StartingValue3 = 5.6 ResetPeriod3 = 5 //Specify no of hour after which to reset optimization Increment3 = 0.2 MaxIncrement3 = 15 //Limit of no of Increment3s either up or down Reps3 = 3 //Number of trades to use for analysis MaxValue3 = 7 //Maximum allowed value MinValue3 = 4 //Minimum allowed value once Dayinit3 = day once Monthinit3 = month If (month = Monthinit3 and day = (Dayinit3 + ResetPeriod3)) or (month = (Monthinit3 + 1) and ((month - Dayinit3) + day = ResetPeriod3)) Then TrailingStart = StartingValue3 WinCountB3 = 0 StratAvgB3 = 0 BestA3 = 0 BestB3 = 0 Dayinit3 = day Monthinit3 = month EndIf once TrailingStart = StartingValue3 once PincPos3 = 1 //Positive Increment3 Position once NincPos3 = 1 //Neative Increment3 Position once optimize3 = 0 ////Initialize Heuristicks Engine Counter (Must be Increment3ed at Position Start or Exit) once Mode3 = 1 //Switches between negative and positive Increment3s //once WinCountB3 = 3 //Initialize Best Win Count //GRAPH WinCountB3 coloured (0,0,0) AS "WinCountB3" //once StratAvgB3 = 4353 //Initialize Best Avg Strategy Profit //GRAPH StratAvgB3 coloured (0,0,0) AS "StratAvgB3" If optimize3 = Reps3 Then WinCountA3 = 0 //Initialize current Win Count StratAvgA3 = 0 //Initialize current Avg Strategy Profit For i3 = 1 to Reps3 Do If positionperf(i3) > 0 Then WinCountA3 = WinCountA3 + 1 //Increment3 Current WinCount EndIf StratAvgA3 = StratAvgA3 + (((PositionPerf(i3)*countofposition[i3]*close)*-1)*-1) Next StratAvgA3 = StratAvgA3/Reps3 //Calculate Current Avg Strategy Profit //Graph (PositionPerf(1)*countofposition[1]*close)*-1 as "PosPerf1" //Graph (PositionPerf(2)*countofposition[2]*close)*-1 as "PosPerf2" //Graph StratAvgA3*-1 as "StratAvgA3" //once BestA3 = 300 //GRAPH BestA3 coloured (0,0,0) AS "BestA3" If StratAvgA3 >= StratAvgB3 Then StratAvgB3 = StratAvgA3 //Update Best Strategy Profit BestA3 = TrailingStart EndIf //once BestB3 = 300 //GRAPH BestB3 coloured (0,0,0) AS "BestB3" If WinCountA3 >= WinCountB3 Then WinCountB3 = WinCountA3 //Update Best Win Count BestB3 = TrailingStart EndIf If WinCountA3 > WinCountB3 and StratAvgA3 > StratAvgB3 Then Mode3 = 0 ElsIf WinCountA3 < WinCountB3 and StratAvgA3 < StratAvgB3 and Mode3 = 1 Then TrailingStart = TrailingStart - (Increment3*NincPos3) NincPos3 = NincPos3 + 1 Mode3 = 2 ElsIf WinCountA3 >= WinCountB3 or StratAvgA3 >= StratAvgB3 and Mode3 = 1 Then TrailingStart = TrailingStart + (Increment3*PincPos3) PincPos3 = PincPos3 + 1 Mode3 = 1 ElsIf WinCountA3 < WinCountB3 and StratAvgA3 < StratAvgB3 and Mode3 = 2 Then TrailingStart = TrailingStart + (Increment3*PincPos3) PincPos3 = PincPos3 + 1 Mode3 = 1 ElsIf WinCountA3 >= WinCountB3 or StratAvgA3 >= StratAvgB3 and Mode3 = 2 Then TrailingStart = TrailingStart - (Increment3*NincPos3) NincPos3 = NincPos3 + 1 Mode3 = 2 EndIf If NincPos3 > MaxIncrement3 or PincPos3 > MaxIncrement3 Then If BestA3 = BestB3 Then TrailingStart = BestA3 Else If Reps3 >= 10 Then WeightedScore3 = 10 Else WeightedScore3 = round((Reps3/100)*100) EndIf TrailingStep = round(((BestA3*(20-WeightedScore3)) + (BestB3*WeightedScore3))/20) //Lower Reps3 = Less weight assigned to Win% EndIf NincPos3 = 1 PincPos3 = 1 ElsIf TrailingStart > MaxValue3 Then TrailingStart = MaxValue3 ElsIf TrailingStart < MinValue3 Then TrailingStart = MinValue3 EndIF optimize3 = 0 EndIf // Heuristics Algorithm 3 End //************************************************************************ // Heuristics Algorithm 4 Start If (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) Then optimize4 = optimize4 + 1 EnDif StartingValue4 = 1.9 ResetPeriod4 = 5 //Specify no of days after which to reset optimization Increment4 = 0.1 MaxIncrement4 = 20 //Limit of no of Increment4s either up or down Reps4 = 3 //Number of trades to use for analysis MaxValue4 = 3 //Maximum allowed value MinValue4 = 1 //Minimum allowed value once Dayinit4 = Day once Monthinit4 = Month If (Month = Monthinit4 and Day = (Dayinit4 + ResetPeriod4)) or (Month = (Monthinit4 + 1) and ((month - Dayinit4) + Day = ResetPeriod4)) Then TrailingStep = StartingValue4 WinCountB4 = 0 StratAvgB4 = 0 BestA4 = 0 BestB4 = 0 Dayinit4 = Day Monthinit4 = Month EndIf once TrailingStep = StartingValue4 once PincPos4 = 1 //Positive Increment4 Position once NincPos4 = 1 //Neative Increment4 Position once optimize4 = 0 ////Initialize Heuristicks Engine Counter (Must be Increment4ed at Position Start or Exit) once Mode4 = 1 //Switches between negative and positive Increment4s //once WinCountB4 = 4 //Initialize Best Win Count //GRAPH WinCountB4 coloured (0,0,0) AS "WinCountB4" //once StratAvgB4 = 4454 //Initialize Best Avg Strategy Profit //GRAPH StratAvgB4 coloured (0,0,0) AS "StratAvgB4" If optimize4 = Reps4 Then WinCountA4 = 0 //Initialize current Win Count StratAvgA4 = 0 //Initialize current Avg Strategy Profit For i4 = 1 to Reps4 Do If positionperf(i4) > 0 Then WinCountA4 = WinCountA4 + 1 //Increment4 Current WinCount EndIf StratAvgA4 = StratAvgA4 + (((PositionPerf(i4)*countofposition[i4]*close)*-1)*-1) Next StratAvgA4 = StratAvgA4/Reps4 //Calculate Current Avg Strategy Profit //Graph (PositionPerf(1)*countofposition[1]*close)*-1 as "PosPerf1" //Graph (PositionPerf(2)*countofposition[2]*close)*-1 as "PosPerf2" //Graph StratAvgA4*-1 as "StratAvgA4" //once BestA4 = 400 //GRAPH BestA4 coloured (0,0,0) AS "BestA4" If StratAvgA4 >= StratAvgB4 Then StratAvgB4 = StratAvgA4 //Update Best Strategy Profit BestA4 = TrailingStep EndIf //once BestB4 = 400 //GRAPH BestB4 coloured (0,0,0) AS "BestB4" If WinCountA4 >= WinCountB4 Then WinCountB4 = WinCountA4 //Update Best Win Count BestB4 = TrailingStep EndIf If WinCountA4 > WinCountB4 and StratAvgA4 > StratAvgB4 Then Mode4 = 0 ElsIf WinCountA4 < WinCountB4 and StratAvgA4 < StratAvgB4 and Mode4 = 1 Then TrailingStep = TrailingStep - (Increment4*NincPos4) NincPos4 = NincPos4 + 1 Mode4 = 2 ElsIf WinCountA4 >= WinCountB4 or StratAvgA4 >= StratAvgB4 and Mode4 = 1 Then TrailingStep = TrailingStep + (Increment4*PincPos4) PincPos4 = PincPos4 + 1 Mode4 = 1 ElsIf WinCountA4 < WinCountB4 and StratAvgA4 < StratAvgB4 and Mode4 = 2 Then TrailingStep = TrailingStep + (Increment4*PincPos4) PincPos4 = PincPos4 + 1 Mode4 = 1 ElsIf WinCountA4 >= WinCountB4 or StratAvgA4 >= StratAvgB4 and Mode4 = 2 Then TrailingStep = TrailingStep - (Increment4*NincPos4) NincPos4 = NincPos4 + 1 Mode4 = 2 EndIf If NincPos4 > MaxIncrement4 or PincPos4 > MaxIncrement4 Then If BestA4 = BestB4 Then TrailingStep = BestA4 Else If Reps4 >= 10 Then WeightedScore4 = 10 Else WeightedScore4 = round((Reps4/100)*100) EndIf TrailingStep = round(((BestA4*(20-WeightedScore4)) + (BestB4*WeightedScore4))/20) //Lower Reps4 = Less weight assigned to Win% EndIf NincPos4 = 1 PincPos4 = 1 ElsIf TrailingStep > MaxValue4 Then TrailingStep = MaxValue4 ElsIf TrailingStep < MinValue4 Then TrailingStep = MinValue4 EndIF optimize4 = 0 EndIf // Heuristics Algorithm 4 End //************************************************************************ //Pivot (H + L + C + O)/4 If OpenDayOfWeek = 1 Then Ht = DHigh(2) Bs = DLow(2) C = DClose(2) O = DOpen(0) Endif If OpenDayOfWeek => 2 and dayofweek < 6 Then Ht = DHigh(1) Bs = DLow(1) C = DClose(1) O = DOpen(0) Endif Pivot = (Ht + Bs + C + O)/4 Res4 = Ht + (3*(Pivot - BS)) Res3 = Ht + (2*(Pivot - Bs)) Res2 = Pivot + (Ht - Bs) Res1 = (2*Pivot) - Bs Sup1 = (2*Pivot) - Ht Sup2 = Pivot-(Ht - Bs) Sup3 = Bs - (2*(Ht - Pivot)) Sup4 = Bs - (3*(Ht - Pivot)) //Heikin-Hachi Once UpDown = 0 IF BarIndex = 0 Then xClose = TotalPrice xOpen = Range xHigh = High xLow = Low Else xClose = TotalPrice xOpen = (xOpen[1] + xClose[1])/2 xHigh = Max(max(high, xOpen), xClose) xLow = Min(min(Low, xOpen), xClose) endif If XClose >= XOpen then if UpDown <> 1 then UpDown = 1 endif Else If UpDown <> -1 then UpDown = -1 endif endif HHSize = 0.6 Distance = 8 LookBack = 8640 //P = 9 // Slope, R², RSI, Sochastic //R2LimE = 0.52 // Coefficient de correlation R² d'entrée //R2LimS = 0.77 // Coefficient de correlation R² de sortie Q = P // Stochastic R = 3 // Stochastic S = 5 // Stochastic SumBull = 2 // Variable Bull SumBear = 2 // Variable Bear // Timeframe SRLevel timeframe (15 minutes, updateonclose) // --- icihmoku support and resistance kijun = (highest[26](high)+lowest[26](low))/2 SSB = (highest[52](high[26])+lowest[52](low[26]))/2 If Kijun = Kijun[1] then KijunPrice = Kijun endif If SSB = SSB[1] then SSBPrice = SSB endif if KijunPrice = SSBPrice then SRLevel = KijunPrice if SRLevel > Close then ResLevel = SRlevel elsif SRLevel < Close then SupLevel = SRlevel endif endif // Timeframe en UT Supérieur Timeframe (3 minutes, updateonclose) SlopeUTSup = Endpointaverage[P](LinearRegressionSlope[P](Close)) If SlopeUTSup > SlopeUTSup[1] then BullUTSup = 1 BearUTSup = 0 Elsif SlopeUTSup < SlopeUTSup[1] then BullUTSup = 0 BearUTSup = -1 endif MyR2Sup = R2[P](Close) If MyR2Sup > R2LimE then AllowedEntry = 1 Elsif MyR2Sup < R2LimE then AllowedEntry = 0 Endif MyRSIUTSup = TriangularAverage[P](RSI[5](Close)) If MyRSIUTSup > MyRSIUTSup[1] then MyRSIUTSupBull = +1 MyRSIUTSupBear = 0 Elsif MyRSIUTSup < MyRSIUTSup[1] then MyRSIUTSupBull = 0 MyRSIUTSupBear = -1 Endif //************************************************************************ //Timeframe en UT de Trading Timeframe (10 seconds, default) if close > pivot then //above Pivot iPivt = 1 while iPivt =< 4 do if iPivt = 1 then Floor = Pivot Ceil = Res1 if close > Floor and close < Ceil then break endif elsif iPivt = 2 then Floor = Res1 Ceil = Res2 if close > Floor and close < Ceil then break endif elsif iPivt = 3 then Floor = Res2 Ceil = Res3 if close > Floor and close < Ceil then break endif elsif iPivt = 4 then Floor = Res3 Ceil = Res4 if close > Floor and close < Ceil then break endif endif iPivt = iPivt + 1 wend elsif close < Pivot then //below Pivot iPivt = 1 while iPivt <= 4 do if iPivt = 1 then Floor = Sup1 Ceil = Pivot if close > Floor and close < Ceil then break endif elsif iPivt = 2 then Floor = Sup2 Ceil = Sup1 if close > Floor and close < Ceil then break endif elsif iPivt = 3 then Floor = Sup3 Ceil = Sup2 if close > Floor and close < Ceil then break endif elsif iPivt = 4 then Floor = Sup4 Ceil = Sup3 if close > Floor and close < Ceil then break endif endif iPivt = iPivt + 1 wend endif EMA13 = EndpointAverage[13](Close) EMA50 = ExponentialAverage[50](Close) If EMA50 > EMA50[1] then Rise = 1 Fall = 0 elsif EMA50 < EMA50[1] then Rise = 0 Fall = -1 endif EMA200 = ExponentialAverage[200](Close) Slope = EndpointAverage[P](LinearRegressionSlope[P](Close)) If Slope > Slope[1] Then Bull = +1 Bear = 0 Elsif Slope < Slope[1] Then Bull = 0 Bear = -1 Endif MyR2 = R2[P](WeightedClose) MyRSI = EndpointAverage[P](RSI[5](Close)) If MyRSI > MyRSI[1] then MyRSIBull = +1 MyRSIBear = 0 Elsif MyRSI < MyRSI[1] then MyRSIBull = 0 MyRSIBear = -1 Endif MyStocK = Stochastic[Q,R](close) MyStocD = WeightedAverage[S](Stochastic[Q,R](close)) If MyStocK > MyStocD Then StocUp = +1 StocDown = 0 Elsif MyStocK < MyStocD Then StocUp = 0 StocDown = -1 Endif //************************************************************************ levier = 2 capital = 500 + (strategyprofit*2/5) z = (capital / (close/20)) * levier //************************************************************************ //Position acheteuse BuyConditionA = (xClose - xOpen)*pipsize => HHSize BuyConditionB = Summation[SumBull](BullUTSup) = SumBull BuyConditionC = Summation[SumBull](AllowedEntry) = Sumbull BuyConditionD = MyRSIUTSup < 76.4 BuyConditionE = summation[SumBull](MyRSIUTSupBull) = SumBull BuyConditionF = EMA50 > EMA200 and EMA50 < Close and summation[5](rise) = 5 BuyConditionG = Summation[SumBull](Bull) = SumBull BuyConditionH = MyRSI < 76.4 BuyConditionI = summation[SumBull](MyRSIBull) = SumBull BuyConditionJ = Summation[SumBull](StocUp) = SumBull and MyStocK < 80 BuyConditionK = MyR2 Crosses over R2LimE BuyConditionL = MyR2 > R2LimE if BuyconditionA and BuyConditionB and BuyConditionC and BuyConditionD and BuyConditionE and BuyConditionF and BuyConditionG and BuyConditionH and BuyConditionI and BuyConditionJ and BuyConditionK and not onmarket and not daysForbiddenEntry then allowtrading = 1 for iSRB = 0 to lookback -1 do dist = (Reslevel[iSRB] - Close) < distance*pipsize if dist then allowtrading = 0 //no trading is allowed we are near a SR! break //break the loop, no need to continue, trading is not allowed anymore! endif next If Close > Pivot or Close < Pivot then For iPivt = 1 to 4 do dist = (Ceil - Close) < distance*pipsize If Dist then allowtrading = 0 Break endif next If BuyConditionL then Entry = Barindex endif if Barindex-Entry <= 2 then if allowtrading then buy z share at market endif endif endif endif If Longonmarket and MyR2Sup crosses under R2LimS then Sell at Market elsif Longonmarket and MyR2Sup crosses under R2LimE then Sell at Market elsif Longonmarket and EMA13 crosses over EMA50 then Sell at Market Endif //Position Vendeuse SellConditionA = (xOpen - xClose)*pipsize => HHSize SellConditionB = Summation[SumBear](BearUTSup) = -SumBear SellConditionC = Summation[SumBull](AllowedEntry) = SumBull SellConditionD = MyRSIUTSup > 23.6 SellConditionE = Summation[SumBear](MyRSIUTSupBear) = -SumBear SellConditionF = EMA50 < EMA200 and EMA50 > Close and summation[5](fall) = -5 SellConditionG = Summation[SumBear](Bear) = -SumBear SellConditionH = MyRSI > 23.6 SellConditionI = Summation[SumBear](MyRSIBear) = -SumBear SellConditionJ = Summation[SumBear](StocDown) = -SumBear and MyStocK > 20 SellConditionK = MyR2 Crosses over R2LimE SellConditionL = MyR2 > R2LimE if SellConditionA and SellconditionB and SellConditionC And SellConditionD and SellConditionE and SellConditionF and SellConditionG and SellConditionH and SellConditionI and SellConditionJ and SellConditionK and not onmarket and not daysForbiddenEntry then allowtrading = 1 for iSRV = 0 to lookback -1 do dist = (close-Suplevel[iSRV]) < distance*pipsize if dist then allowtrading = 0 //no trading is allowed we are near a SR! break //break the loop, no need to continue, trading is not allowed anymore! endif next If Close > Pivot or Close < Pivot then For iPivt = 1 to 4 do dist = (Close - Floor) < distance*pipsize If Dist then allowtrading = 0 Break endif next if SellConditionL then Entry = Barindex endif If Barindex-Entry <= 2 then if allowtrading then sellshort z share at market endif endif endif endif If Shortonmarket and MyR2Sup crosses under R2LimS then Exitshort at market elsif Shortonmarket and MyR2Sup crosses under R2LimE then Exitshort at market elsif Shortonmarket and EMA13 crosses over EMA50 then Exitshort at market Endif //************************************************************************ //Stop Loss & Trailing function //Set stop $loss capital*levier*4/100 Set Target $Profit capital*levier*8/100 //reset the stoploss value If not onmarket then newSL = 0 Endif //manage long positions If Longonmarket Then If newSL = 0 and xLow-tradeprice(1) > trailingstart*pipsize then newSL = tradeprice(1) + trailingstep*pipsize Endif If newSL <> 0 and xLow-newSL > trailingstep*pipsize then newSL = newSL + trailingstep*pipsize Endif Endif //manage short positions If ShortonMarket then If newSL = 0 and tradeprice(1)-xHigh > trailingstart*pipsize Then newSL = tradeprice(1) - trailingstep*pipsize Endif If newSL <> 0 and newSL-xHigh > trailingstep*pipsize Then newSL = newSL - trailingstep*pipsize Endif Endif //stop order to exit the positions If newSL <> 0 Then Sell at newSL Stop Exitshort at newSL Stop Endif //************************************************************************