|
|
@@ -101,6 +101,11 @@ input bool enableTimeSession = false;
|
|
101
|
101
|
input string start_time_session = "01:00"; // Start Session
|
|
102
|
102
|
input string end_time_session = "23:59"; // End Session
|
|
103
|
103
|
|
|
|
104
|
+input string string_0_2 = "<><><><><><> Trailing Setting<><><><><><>"; //__
|
|
|
105
|
+input bool indivial_trailing = false; // Indiviual Trailing
|
|
|
106
|
+input double ts_sl = 15; // Trailing Start in Pips
|
|
|
107
|
+input double ts = 5; // Trailing Stop in Pips
|
|
|
108
|
+
|
|
104
|
109
|
input string news = "<><><><><><> News Settings <><><><><><>"; // News
|
|
105
|
110
|
input NewsCloseOrder newsClose = CloseAllRunningOrder; // On News Action on Running Orders
|
|
106
|
111
|
input bool High_Impact_News = true; //High Impact News
|
|
|
@@ -234,7 +239,7 @@ void OnDeinit(const int reason)
|
|
234
|
239
|
//+------------------------------------------------------------------+
|
|
235
|
240
|
void OnTick()
|
|
236
|
241
|
{
|
|
237
|
|
- static int status=-1,preStatus=-1;
|
|
|
242
|
+ static int status=-1,preStatus=-1;
|
|
238
|
243
|
if(!MQLInfoInteger(MQL_TESTER))
|
|
239
|
244
|
{
|
|
240
|
245
|
status=returnNewsStatus(High_Impact_News
|
|
|
@@ -349,6 +354,10 @@ void OnTick()
|
|
349
|
354
|
void mainActivity()
|
|
350
|
355
|
{
|
|
351
|
356
|
//---
|
|
|
357
|
+ if(indivial_trailing)
|
|
|
358
|
+ {
|
|
|
359
|
+ Individual_Trailing();
|
|
|
360
|
+ }
|
|
352
|
361
|
double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);
|
|
353
|
362
|
double Ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
|
|
354
|
363
|
|
|
|
@@ -866,5 +875,64 @@ bool spreadFilter()
|
|
866
|
875
|
//+------------------------------------------------------------------+
|
|
867
|
876
|
//| |
|
|
868
|
877
|
//+------------------------------------------------------------------+
|
|
|
878
|
+void Individual_Trailing()
|
|
|
879
|
+ {
|
|
|
880
|
+ int openedpositions;
|
|
|
881
|
+ double mySL,myResult;
|
|
|
882
|
+
|
|
|
883
|
+ openedpositions=PositionsTotal();
|
|
|
884
|
+ if((openedpositions>0))
|
|
|
885
|
+ {
|
|
|
886
|
+ int totalorders=PositionsTotal();
|
|
|
887
|
+ for(int i=0; i<totalorders; i++) // scan all orders and positions. ..
|
|
|
888
|
+ {
|
|
|
889
|
+ ulong ticket = PositionGetTicket(i);
|
|
|
890
|
+ if(PositionSelectByTicket(ticket))
|
|
|
891
|
+ {
|
|
|
892
|
+ if(PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_MAGIC) ==magic_no) // only look if mygrid and symbol. ..
|
|
|
893
|
+ {
|
|
|
894
|
+
|
|
|
895
|
+ double SymbolAsk = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_ASK);
|
|
|
896
|
+ double SymbolBid = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_BID);
|
|
|
897
|
+ int SymbolDigits = (int)SymbolInfoInteger(PositionGetString(POSITION_SYMBOL), SYMBOL_DIGITS);
|
|
|
898
|
+ double SymbolTickSize = SymbolInfoDouble(PositionGetString(POSITION_SYMBOL), SYMBOL_TRADE_TICK_SIZE);
|
|
|
899
|
+ int type= (int)PositionGetInteger(POSITION_TYPE);
|
|
|
900
|
+
|
|
|
901
|
+ if(type==POSITION_TYPE_BUY) // its a long position
|
|
|
902
|
+ {
|
|
|
903
|
+ mySL=NormalizeDouble(SymbolAsk-(ts*SymbolTickSize*10),Digits()); // new SL
|
|
|
904
|
+ double startSl=PositionGetDouble(POSITION_PRICE_OPEN)+(ts_sl*SymbolTickSize*10);
|
|
|
905
|
+ if(PositionGetDouble(POSITION_SL) != mySL)
|
|
|
906
|
+ if(mySL>PositionGetDouble(POSITION_SL) && SymbolAsk>=startSl)
|
|
|
907
|
+ {
|
|
|
908
|
+ myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrGreen);
|
|
|
909
|
+ if(!myResult)
|
|
|
910
|
+ {
|
|
|
911
|
+ Print(" Buy Trade Trailing Error: ",GetLastError());
|
|
|
912
|
+ }
|
|
|
913
|
+ }
|
|
|
914
|
+ }
|
|
|
915
|
+ if(type==POSITION_TYPE_SELL)
|
|
|
916
|
+ {
|
|
|
917
|
+ mySL=NormalizeDouble(SymbolBid+(ts*SymbolTickSize*10),Digits()); // new SL
|
|
|
918
|
+ double startSlSell=PositionGetDouble(POSITION_PRICE_OPEN)-(ts_sl*SymbolTickSize*10);
|
|
|
919
|
+ if(PositionGetDouble(POSITION_SL) != mySL)
|
|
|
920
|
+ if(((mySL<PositionGetDouble(POSITION_SL)) || (PositionGetDouble(POSITION_SL)<SymbolTickSize)) && SymbolBid<=startSlSell)
|
|
|
921
|
+ {
|
|
|
922
|
+ myResult=trade.PositionModify(ticket,mySL,PositionGetDouble(POSITION_TP)); //OrderModify(OrderTicket(),OrderOpenPrice(),mySL,OrderTakeProfit(),0,clrRed);
|
|
|
923
|
+ if(!myResult)
|
|
|
924
|
+ {
|
|
|
925
|
+ Print(" Sell Trade Trailing Error: ",GetLastError());
|
|
|
926
|
+ }
|
|
|
927
|
+ }
|
|
|
928
|
+ }
|
|
|
929
|
+ }
|
|
|
930
|
+ }
|
|
|
931
|
+ }
|
|
|
932
|
+ }
|
|
|
933
|
+ }
|
|
|
934
|
+//+------------------------------------------------------------------+
|
|
|
935
|
+//| |
|
|
|
936
|
+//+------------------------------------------------------------------+
|
|
869
|
937
|
|
|
870
|
938
|
//+------------------------------------------------------------------+
|