/*[[ Name := IshimokuAutoTrader Author := Pereslavtsev Aleksandr Link := http://www.company.com/ Notes := Update on every tick := Yes Enable Alerts := No Disable alert once hit := No Lots := 2 Stop Loss := 160 Take Profit := 300 Trailing Stop := 130 ]]*/ Variables: TS1(0),TS2(0),TS(0),KS1(0),KS2(0),KS(0),CHS(0),Temp1(0),Temp2(0); Defines: TsP(9),TsSh(9),KsP(26),KsSh(26),InLowBuy(35),InHighBuy(27),InLowSell(26),InHighSell(35); Defines: OutLowBuy(26),OutHighBuy(29),OutLowSell(29),OutHighSell(26),Delta(3),Alfa(21),Delta1(3),Alfa1(3); Vars:cnt(0),cnt1(0),first(0); /* TS1 (0) - the Price of opening of the maximal bar from 9 since current +1---| TS2 (0) - the Price of closing of the maximal bar from 9 since current +1 |TenkanSen TS (0) - the Average price of the maximal bar from 9 since current +1-----| KS1 (0) - the Price of opening of the maximal bar from 26 since current +1---| KS2 (0) - the Price of closing of the maximal bar from 26 since current +1 |KenzhunSen KS (0) - the Average price of the maximal bar from 26 since current +1-----| CHS (0) - CHinkouSpan Temp1 (0) - abs (TS1-TS2)/2 Temp2 (0) - abs (KS1-KS2)/2 TsP-Tenkan-sen the Period TsSh - Tenkan-sen Shift KsP - Kenzhun-sen the Period KsSh - Kenzhun-sen Shift InLowBuy (28) - Number of bar Low for an input on BUY InHighBuy (26) - Number of bar High for an input on BUY InLowSell (26) - Number of bar Low for an input on SELL InHighSell (28) - Number of bar High for an input on SELL OutLowBuy (26) - Number of bar Low for an output on BUY OutHighBuy (29) - Number of bar High for an output on BUY OutLowSell (29) - Number of bar Low for an output on SELL OutHighSell (26) - Number of bar High for an output on SELL */ // We count TS1 TS1=Open[Highest(MODE_OPEN,TsSh,TsP)]; //We count TS2 TS2=Close[Highest(MODE_OPEN,TsSh,TsP)]; // We null Temp1 Temp1=0; // We calculate TS If TS1>TS2 then { Temp1=(TS1-TS2)/2; TS=TS1//-Temp1; } else { Temp1=(TS2-TS1)/2; TS=TS1//+Temp1; }; // We count KS1 KS1=Open[Highest(MODE_OPEN,KsSh,KsP)]; //We count KS2 KS2=Close[Highest(MODE_OPEN,KsSh,KsP)]; // We null Temp2 Temp2=0; // We calculate KS If KS1>KS2 then { Temp2=(KS1-KS2)/2; KS=KS1;//-Temp2; } else { Temp2=(KS2-KS1)/2; KS=KS1;//+Temp2; }; //Задаем CHS CHS=Close[0]; //Print("TS=",TS," KS=",KS," CHS=",CHS," High=",High[InHighBuy]," Low=",Low[InLowBuy]); // Primary checks of the data // It is important to make sure that the expert works on the normal schedule and // The user has correctly exposed external variables (Lots, StopLoss, // TakeProfit, TrailingStop) // In our case it is checked only TakeProfit If (Bars<200 or TakeProfit<10) then Exit; // On the schedule less than 200 bars // Since time of last operation has passed bolshe hour? If (CurTime-LastTradeTime)<3600 then exit; // Let's check up, whether there are earlier open positions or ordery? If TotalTrades<2 then { // If Balance>50000 then lots=lots+1;// Just in case we shall check up, if at us free money for the account? // Value 1000 is taken for an example, it is usually possible to open 1 lot If FreeMargin<500 then Exit; // Money is not present - we leave // We check on an opportunity to rise in a long position (BUY) If (CHS<=Low[InLowSell] and CHS>=High[InHighSell] and TS<=KS-Delta1*Point) And Close[0]=High[InHighBuy] And CHS<=Low[InLowBuy] and TS<=KS+Delta*Point) and Open[0]>KS+Alfa*Point and (Ask+Bid)/2>Open[4] and (Ask+Bid)/2>Open[3] and (Ask+Bid)/2>Open[2] and (Ask+Bid)/2>Open[0] then { If (CurTime-LastTradeTime)<3600 then exit; SetOrder(OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,LightBlue); // We execute Exit; // We leave }; // Here we have finished check on an opportunity of opening of new positions. }; // We move stops if TrailingStop<5 then { print("Invalid trailing stop"); Exit; }; /* We check earlier open positions. Trailing stop works through updating Stop Loss. */ for cnt1=1 to TotalTrades begin /* It is a long position? */ If Ord(cnt1,VAL_TYPE)=OP_BUY then /* Long position */ { /* First we shall check up - whether is profit at this transaction more than Level trailing stop? We check Bid, as position BUY */ If (Bid-Ord(cnt1,VAL_OPENPRICE))>(TrailingStop*Point) then { /* Yes, the position has profit more than value trailing stop (for example 30 items). Now it is necessary to check up, whether it is possible To put stop it is better than it was earlier? */ If Ord(cnt1,VAL_STOPLOSS)<(Bid-TrailingStop*Point) then { /* We change stoploss for a level Bid-Trailing Stop */ ModifyOrder(Ord(cnt1,VAL_TICKET),Ord(cnt1,VAL_OPENPRICE), Bid-TrailingStop*Point,Ord(cnt1,VAL_TAKEPROFIT),Yellow); Exit; /* Business have made - we leave. */ }; }; }; /* It is a short position? */ If Ord(cnt1,VAL_TYPE)=OP_SELL then { /* First we shall check up - whether is profit at this transaction more than Level trailing stop? We check Ask, as a position SELL */ If (Ord(cnt1,VAL_OPENPRICE)-Ask)>(TrailingStop*Point) then { /* Yes, the position has profit more than value trailing stop (for example 30 items). Now it is necessary to check up, whether it is possible To put stop it is better than it was earlier? */ If Ord(cnt1,VAL_STOPLOSS)>(Ask+TrailingStop*Point) or Ord(cnt1,VAL_STOPLOSS)=0 then /* Obligatory condition!!! */ { /* We change stoploss for a level Ask+Trailing Stop */ ModifyOrder(Ord(cnt1,VAL_TICKET),Ord(cnt1,VAL_OPENPRICE), Ask+TrailingStop*Point,Ord(cnt1,VAL_TAKEPROFIT),Red); Exit; }; }; }; end; // We check, it can is already necessary to leave? for cnt=1 to TotalTrades { if OrderValue(cnt,VAL_TYPE)<=OP_SELL and // It is an open position? OP_BUY Or OP_SELL OrderValue(cnt,VAL_SYMBOL)=Symbol then // The tool coincides? { If OrderValue(cnt,VAL_TYPE)=OP_BUY then // The long position is open { // Let's check up, can it is time already be closed? If (CHS<=Low[OutLowBuy] and CHS>=High[OutHighBuy]) and TSKS then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet); // We close a position Exit; // We leave }; } else // Otherwise it is a short position { // Let's check up, can it is time already be closed? If (CHS>=High[OutHighSell] and CHS<=Low[OutLowSell]) and TS>KS and Close[0]>KS then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); // We close a position Exit; // We leave }; }; }; };