Specifiche
Ø Section 1 – Indicator script (Note that this section 1 script is important for the EA describe in Section 2 below)
This indicator script outputs the following variable:
PriceHighBox = #Price_level
PriceLowBox = #Price_level
SRBox = up or down
Draw red and blue dots to indicate support and resistance
Valid scenario A:
A peak has to rise up and down in price by Y amount of pips (user input). Vice versa for support.
[A: The highest price of 3 peaks (for uptrend; 3 peaks cannot be consecutively higher) with [B: one identified support or resistance] that has a [C: clearance more than X pips]. Draw [D: blue dot (below low)] and [E: red dot (above high)] on chart. (see graphic below)
Valid scenario B:
[A: The Lowest price of 3 supports (for downtrend; 3 supports cannot be consecutively lower) with [B: one identified peak] that has a [C: clearance more than X pips]. Draw [D: blue dot (below low)] and [E: red dot (above high)] on chart. (see graphic below)
Valid scenario C:
[A: The highest price of 3 peaks (for downtrend; 3 peaks cannot be consecutively lower) with [B: one identified support] that has a [C: clearance more than X pips]. Draw [D: blue dot (below low)] and [E: red dot (above high)] on chart. (see graphic below)
Valid scenario D:
[A: The Lowest price of 3 supports (for uptrend; 3 supports cannot be consecutively higher) with [B: one identified peak] that has a [C: clearance more than X pips]. Draw [D: blue dot (below low)] and [E: red dot (above high)] on chart. (see graphic below)
When the indicator becomes invalid
Invalid scenario A:
Invalid scenario B:
Invalid scenario C:
Invalid scenario D:
Ø Section 2 – EA Program:
PairSpread //Fixed
spread of instrument input by user
SRBox
ExistingTrade = False //At the start
of the program, existing trade will be false i.e. none. It has 3 states: None,
Long, Short
SupportPrice = 0 //Lowest
price as determined by SRBox indicator
ResistancePrice = 0 //Highest
price as determined by SRBox indicator
PercentTriggerBuffer //Percent input
by user to be applied on SupportPrice and ResistancePrice to determine stop
trigger//
TriggerBuffer //TriggerBuffer = PercentTriggerBuffer * (ResistancePrice –SupportPrice)
SplitBlock //Dividing the whole box including two sides of the buffer by 10, SplitBlock = [(ResistancePrice – SupportPrice) + 2*TriggerBuffer]/10
PF[1] = 5, PF[2] = 6, PF[3] = 6, PF[4] = 6, PF[5] = 6, PF[6], PF[7] = 7, PF[8] = 8, PF[9] = 9, PF[10] =10 //Number input by user for target profit calculation
BStop[1] //
First trade: Buy stop order, BStop1 = ResistancePrice + TriggerBuffer +
PairSpread;
BStopSLoss[N] // Stop loss for first
trade: BStopSLoss [N]= BStop1 – N*SplitBlock
SStopSLoss[N] // Stop loss for first
trade: SStopSLoss [N]= BStop1 + N*SplitBlock
BTargetProfit[N]// Buy target profit for first trade: BTargetProfit[1] = PF[1]*SplitBlock
+ PairSpread
PercentRisk[1], PercentRisk[2], PercentRisk[3], PercentRisk[4],
PercentRisk[5], PercentRisk[6], PercentRisk[7], PercentRisk[8], PercentRisk[9],
PercentRisk[10]
//User input on percentage in decimals to indicate how much capital to risks,
use to calculate lot size
N = 1 //
number of trade
LotSize1 // Lot size
calculation based on PercentRisk1 of capital
MarketBuy2 // 2nd trade
which is a market buy
Ø Process 1: SRBox Script from Section to assign support and resistance price
//Identify latest valid SR box for both up and down based on rule describe in section 1.
Use indicator from section 1
PriceHighBoxUp = #Highest price of the up box
PriceLowBoxUp = #Lowest price of the up box
PriceHighBoxDown = #Highest price of the Down box
PriceLowBoxDown = #Lowest price of the Down box
SplitBlockUpNew = [(PriceHighBoxUp – PriceLowBoxUp)*(1+ PercentTriggerBuffer)]/10
SplitBlockDownNew = [(PriceHighBoxDown – PriceLowBoxDown) *(1+ PercentTriggerBuffer)]
/10
Ø Process 2: Calculate Buy and Sell stop level, stop loss and target profit (for both long and short)
ResistancePrice = PriceHighBoxUp
ResistanceBasePrice = PriceLowBoxUp
SupportPrice = PriceLowBoxDown
SupportBasePrice = PriceHighBoxDown
BStop[1] = ResistancePrice + TriggerBuffer + PairSpread;
BTargetProfit[1] = BStop[1] + PF[1]*SplitBlock + PairSpread
BStopSLoss[1] = BStop[1] – SplitBlock
SStop[1] = SupportPrice - TriggerBuffer;
STargetProfit[1] = SStop[1] – (PF[1]*SplitBlock + PairSpread)
SStopSLoss[1]= SStop[1] + SplitBlock
Ø Process 3: Activate price levels (for both long and short)
If [ExistingTrade != long]
{BuyStop @ BStop[1] with Stop Loss @ BStopSLoss[1] and BTargetProfit[1];
LotSize[1]
IF BStop[1] is executed, CLOSE previous short trade if exists, ExistingTrade = long, N=1}
If [ExistingTrade != short]
{SellStop @ SStop[1] with Stop Loss @ SStopSLoss[1] and STargetProfit[1];
LotSize[1]
IF SStop[1] is executed, CLOSE previous long trade if exists, ExistingTrade = short, N=1}
Ø Process Step 4: Activate Martingale for orders taken
//If the first trade is taken and stop loss of first trade is hit, continue taking trade in the same direction but martingale the risks. Take trade in the same direction only up to a maximum of 10 times.
If ExistingTrade = Long && If BStopSLoss[N] is hit &&
N <=10, N++
{ BStop[N] = ResistancePrice + N*TriggerBuffer + PairSpread;
BTargetProfit[N] = BStop[N] + PF[N]*SplitBlock + PairSpread
BStopSLoss[N] = BStop[N] – SplitBlock
MarketBuy[N] with BStopSLoss[N], BTargetProfit[N], LotSize[N]}
If ExistingTrade = short && If SStopSLoss[N] is hit &&
N <=10, N++
{ SStop[N] = SupportPrice - TriggerBuffer;
STargetProfit[N] = SStop[N] – (PF[N]*SplitBlock + PairSpread)
SStopSLoss[N]= SStop[N] + SplitBlock
MarketSell[N] with SStopSLoss[N], STargetProfitN], LotSize[N]}
Ø Process Step 5 (Final): Reset everything
If Target profit is hit, N = 0, ExistingTrade = False
End.