Max Spread for an EA

Einloggen oder registrieren, um einen Kommentar zu schreiben
Dennis Juergen Schnurpfeil
394
Dennis Juergen Schnurpfeil  

Hello, 

I have an Simple RSI Indicator who buys and sells when RSI reaches a special point.

How can I add the option that it wont trade when spread is like higher than 6 or something else.

This is the Code:


Hello I have an Simple RSI Indicator wo sell and buys when RSI reaches some point. 

Now I dont want it to make orders, when the Spread is maybe higher than 6 or 7 Points just for example.

So It should be added the option for max Spread.

This is the Code from the RSI Indicator:


//+------------------------------------------------------------------+

//|                                                       RSI EA.mq4 |

//|                        Copyright 2015, MetaQuotes Software Corp. |

//|                         

//+------------------------------------------------------------------+

#property copyright "Copyright 2015, dXerof"

#property link      "http://free-bonus-deposit.blogspot.com"

#property version   "1.00"

#property strict


input bool   OpenBUY=True;

input bool   OpenSELL=True;

input bool   CloseBySignal=True;

input double StopLoss=0;

input double TakeProfit=0;

input double TrailingStop=0;

input int    RSIperiod=14;

input double BuyLevel=30;

input double SellLevel=70;

input bool   AutoLot=True;

input double Risk=10;

input double ManualLots=0.1;

input int    MagicNumber=123;

input string Koment="RSIea";

input int    Slippage=10;

//---

int OrderBuy,OrderSell;

int ticket;

int LotDigits;

double Trail,iTrailingStop;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int init()

  {

   return(0);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int deinit()

  {

   return(0);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int start()

  {

   double stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);

   OrderBuy=0;

   OrderSell=0;

   for(int cnt=0; cnt<OrdersTotal(); cnt++)

     {

      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && OrderComment()==Koment)

           {

            if(OrderType()==OP_BUY) OrderBuy++;

            if(OrderType()==OP_SELL) OrderSell++;

            if(TrailingStop>0)

              {

               iTrailingStop=TrailingStop;

               if(TrailingStop<stoplevel) iTrailingStop=stoplevel;

               Trail=iTrailingStop*Point;

               double tsbuy=NormalizeDouble(Bid-Trail,Digits);

               double tssell=NormalizeDouble(Ask+Trail,Digits);

               if(OrderType()==OP_BUY && Bid-OrderOpenPrice()>Trail && Bid-OrderStopLoss()>Trail)

                 {

                  ticket=OrderModify(OrderTicket(),OrderOpenPrice(),tsbuy,OrderTakeProfit(),0,Blue);

                 }

               if(OrderType()==OP_SELL && OrderOpenPrice()-Ask>Trail && (OrderStopLoss()-Ask>Trail || OrderStopLoss()==0))

                 {

                  ticket=OrderModify(OrderTicket(),OrderOpenPrice(),tssell,OrderTakeProfit(),0,Blue);

                 }

              }

           }

     }

   double rsi=iRSI(Symbol(),0,RSIperiod,PRICE_CLOSE,0);

   double rsi1=iRSI(Symbol(),0,RSIperiod,PRICE_CLOSE,1);

// double HTb=iCustom(Symbol(),0,"HalfTrend-1.02",0,0); //buy

// double HTs=iCustom(Symbol(),0,"HalfTrend-1.02",1,0); //buy

//--- open position

   if(OpenSELL && OrderSell<1 && rsi<SellLevel && rsi1>SellLevel) OPSELL();

   if(OpenBUY && OrderBuy<1 && rsi>BuyLevel && rsi1<BuyLevel) OPBUY();

//--- close position by signal

   if(CloseBySignal)

     {

      if(OrderBuy>0 && rsi<SellLevel && rsi1>SellLevel) CloseBuy();

      if(OrderSell>0 && rsi>BuyLevel && rsi1<BuyLevel) CloseSell();

     }

//---

   return(0);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OPBUY()

  {

   double StopLossLevel;

   double TakeProfitLevel;

   if(StopLoss>0) StopLossLevel=Bid-StopLoss*Point; else StopLossLevel=0.0;

   if(TakeProfit>0) TakeProfitLevel=Ask+TakeProfit*Point; else TakeProfitLevel=0.0;


   ticket=OrderSend(Symbol(),OP_BUY,LOT(),Ask,Slippage,StopLossLevel,TakeProfitLevel,Koment,MagicNumber,0,DodgerBlue);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void OPSELL()

  {

   double StopLossLevel;

   double TakeProfitLevel;

   if(StopLoss>0) StopLossLevel=Ask+StopLoss*Point; else StopLossLevel=0.0;

   if(TakeProfit>0) TakeProfitLevel=Bid-TakeProfit*Point; else TakeProfitLevel=0.0;

//---

   ticket=OrderSend(Symbol(),OP_SELL,LOT(),Bid,Slippage,StopLossLevel,TakeProfitLevel,Koment,MagicNumber,0,DeepPink);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void CloseSell()

  {

   int  total=OrdersTotal();

   for(int y=OrdersTotal()-1; y>=0; y--)

     {

      if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))

         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==MagicNumber)

           {

            ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Black);

           }

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

void CloseBuy()

  {

   int  total=OrdersTotal();

   for(int y=OrdersTotal()-1; y>=0; y--)

     {

      if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES))

         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==MagicNumber)

           {

            ticket=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),5,Black);

           }

     }

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

double LOT()

  {

   double lotsi;

   double ilot_max =MarketInfo(Symbol(),MODE_MAXLOT);

   double ilot_min =MarketInfo(Symbol(),MODE_MINLOT);

   double tick=MarketInfo(Symbol(),MODE_TICKVALUE);

//---

   double  myAccount=AccountBalance();

//---

   if(ilot_min==0.01) LotDigits=2;

   if(ilot_min==0.1) LotDigits=1;

   if(ilot_min==1) LotDigits=0;

//---

   if(AutoLot)

     {

      lotsi=NormalizeDouble((myAccount*Risk)/10000,LotDigits);

        } else { lotsi=ManualLots;

     }

//---

   if(lotsi>=ilot_max) { lotsi=ilot_max; }

//---

   return(lotsi);

  }

//+------------------------------------------------------------------+


Carl Schreiber
Moderator
9790
Carl Schreiber  

In der Dok. (merk Dir den Link vielleicht) such mal nach spread  (mit ctrl+f).

Wenn Du den Spread mittels CopySpread() hast (Tipp: nimm immer nur einen Wert) ganz einfach ein 

if (spread[0]<=MaxSpread) { /* trade */ }
Dokumentation zu MQL5: MQL5 Funktionenliste
Dokumentation zu MQL5: MQL5 Funktionenliste
  • www.mql5.com
Fügt Daten aus einem Array vom Typ MqlTick in die Preishistorie eines benutzerdefinierten Symbols hinzu. Das benutzerdefinierte Symbol muss im Fenster MarketWatch (Marktübersicht) ausgewählt werden Liest aus der Datei des Typs CSV die Zeile eines der Formate: "YYYY.MM.DD HH:MI:SS", "YYYY.MM.DD" oder "HH:MI:SS" - und wandelt sie...
Dennis Juergen Schnurpfeil
394
Dennis Juergen Schnurpfeil  

Hallo Vielen Dank!


Ich habe mich allerdings noch kein bisschen mit dem programmieren beschäftigt. Einfach einfügen klappt nicht in den Code? Ist das viel Aufwand? Sollte ich das über Freelance machen lassen?

Otto Pauser
2165
Otto Pauser  

Es ist sehr depremierend :(

Keine Ahnung vom Programmieren, keine Ahnung vom Traden, keine Ahnung von Code formatieren und hier den Stein der Weisen finden wollen!

Dennis Juergen Schnurpfeil
394
Dennis Juergen Schnurpfeil  
Otto Pauser:

Es ist sehr depremierend :(

Keine Ahnung vom Programmieren, keine Ahnung vom Traden, keine Ahnung von Code formatieren und hier den Stein der Weisen finden wollen!

Vom Traden habe ich mehr als Ahnung. Aber warum soll ich noch Jahre investieren um programmieren zu lernen? 
Carl Schreiber
Moderator
9790
Carl Schreiber  

Dann wären die Freelancer die besseren Ansprechpartner.

Aber besser erst dies lesen:

https://www.mql5.com/de/job/rules     // rules
https://www.mql5.com/de/articles/4368 // EA
https://www.mql5.com/de/articles/4304 // Indi

Handelsanwendungen für MetaTrader 5 auf Bestellung
Handelsanwendungen für MetaTrader 5 auf Bestellung
  • www.mql5.com
Hello Arkadii, I hope you are well! I have a new order for you :-) Can you change the attached EA that you developed for me some time ago? I would like to determine the take profit myself, i.e. I would like to determine the candle with which the trade is closed, just as with the stopploss, also with the take profit, regardless of whether the...
Einloggen oder registrieren, um einen Kommentar zu schreiben