Coding help - page 657

 

Dear friends,

Does this ea work on different pairs at the some time?

For example: at the some time working EURUSD + GBPUSD etc.

Thank you... 

Files:
 
oguz:

Dear friends,

Does this ea work on different pairs at the some time?

For example: at the some time working EURUSD + GBPUSD etc.

Thank you... 

Attach it to different charts with different magic numbers and it should work OK. Otherwise, judging from the code, you can have a major mixup
 
mladen:
Attach it to different charts with different magic numbers and it should work OK. Otherwise, judging from the code, you can have a major mixup

Thank you very much detailed info.

 

By the way can we attach any number as magic number?

Its default Magic Number is: "288"

Can i attach it: 398, 477, 501, 875 etc. ?  

 

Dear Mladen ,

May i know how can i add the opposite signal close to the code ?

extern bool oppositeSignalclose=true;


i have try it but it close on every bar .


Can you help me to see what should i need to change for the  "OrderSended" close all sell after buy / close all buy after sell .

Thank you .

  // New buy orders
  TotalBuyOrders = CountOfOrders(MagicNumberBuy);
  if(TotalBuyOrders > 0 && TotalBuyOrders < MaxTrades)
  {
    OrderSended = -1;
    LastSellPrice = FindLastOrderParameter(MagicNumberBuy, "price");

    if(LastSellPrice - Ask >= GetPipstepForStep(TotalBuyOrders + 1) * vPoint)
    {
      BLot   = GetLotForStep(MagicNumberBuy, TotalBuyOrders);
      BComment = StringSubstr(LastOrderComment, 0, StringFind(LastOrderComment, "|", 0)) + "|";
      OrderSended = SendMarketOrder(OP_BUY, BLot, 0, 0, MagicNumberBuy, BComment);
    }
  }
  // New sell orders
  TotalSellOrders = CountOfOrders(MagicNumberSell);
  if(TotalSellOrders > 0 && TotalSellOrders < MaxTrades)
  {
    OrderSended = -1;
    LastBuyPrice = FindLastOrderParameter(MagicNumberSell, "price");

    if (Bid - LastBuyPrice >= GetPipstepForStep(TotalSellOrders + 1) * vPoint) 
    {
      SLot   = GetLotForStep(MagicNumberSell, TotalSellOrders);
      SComment = StringSubstr(LastOrderComment, 0, StringFind(LastOrderComment, "|", 0)) + "|";
      OrderSended = SendMarketOrder(OP_SELL, SLot, 0, 0, MagicNumberSell, SComment);
    }
  }
 
stevenpun:

Dear Mladen ,

May i know how can i add the opposite signal close to the code ?


i have try it but it close on every bar .


Can you help me to see what should i need to change for the  "OrderSended" close all sell after buy / close all buy after sell .

Thank you .

Invert the call to CountOfOrders if the oppositeSignalclose is set to true (ie, something like this :

if (oppositeSignalclose)
      TotalBuyOrders = CountOfOrders(MagicNumberBuy);
else  TotalBuyOrders = CountOfOrders(MagicNumberSell);
And do the same for sell orders too
 
mladen:

Invert the call to CountOfOrders if the oppositeSignalclose is set to true (ie, something like this :

And do the same for sell orders too

It this a reverse trade ?

I want the current trade close when opposite signal .

I find one of the code on net , but it close on each bar .

Can you help me to check is that did i insert the correct way or different things that i want .

And the candle trailing stop , i have did what you teach me on last week but still cant work .

extern bool oppositeclose=true;
if((oppositeclose && sell))closebuy();
if((oppositeclose && buy))closesell();
//|---------close

void closebuy(){
   RefreshRates();
   if(OrdersTotal()>0){
      for(int i=OrdersTotal();i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY){
            OrderClose(OrderTicket(),OrderLots(),Bid,slippage*mt);
         }
      }
   }
}

void closesell(){
   RefreshRates();
   if(OrdersTotal()>0){
      for(int i=OrdersTotal();i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL){
            OrderClose(OrderTicket(),OrderLots(),Ask,slippage*mt);
         }
      }
   }
}
Files:
BbandTest.mq4  37 kb
 
stevenpun:

It this a reverse trade ?

I want the current trade close when opposite signal .

I find one of the code on net , but it close on each bar .

Can you help me to check is that did i insert the correct way or different things that i want .

And the candle trailing stop , i have did what you teach me on last week but still cant work .

As far as I see, that should be correct
 

Please help me whith code of export indicators to .csv
It allows write just one indicator...

What should be corrected to export multiple data columns after OHLC ..?

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

//|                                                  RSI_to_File.mq4 |

//|                      Copyright © 2007, MetaQuotes Software Corp. |

//|                                        [url]http://www.metaquotes.ru/[/url] |

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

#property copyright "Copyright © 2007, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.ru/"


#property show_inputs

string SymbolsArray[13]={"","GBPUSD","EURUSD"};


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

//| string SymbolByNumber                                   |

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

string GetSymbolString(int Number)

  {

//----

   string res="";

   res=SymbolsArray[Number];   

//----

   return(res);

  }


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

//| возвращает период                                                |

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

int PeriodNumber(int number)

   {

   int per_min;

   switch (number)

      {

      default: per_min=PERIOD_M1;break;

      case 1: per_min=PERIOD_M5;break;

      case 2: per_min=PERIOD_M12;break;

      }

   return(per_min);   

   }


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

//|   выводит в файл котировки + значения индикатора                 |

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

void IFT_output(string SymbolName,int PeriodMinutes)

   {

   int size=iBars(SymbolName,PeriodMinutes);

//----

   if (size==0) return;

   int handle=FileOpen(SymbolName+PeriodMinutes+"_IFT.csv",FILE_WRITE|FILE_CSV);

   if (handle<0) return;

   FileWrite(handle,"Time seconds;Time;Open;Low;High;Close;Volume;IFT");

   for (int i=size-1;i>=0;i--)

      {

      FileWrite(handle,iTime(SymbolName,PeriodMinutes,i),TimeToStr(iTime(SymbolName,PeriodMinutes,i))

         ,iOpen(SymbolName,PeriodMinutes,i),iLow(SymbolName,PeriodMinutes,i),iHigh(SymbolName,PeriodMinutes,i)

         ,iClose(SymbolName,PeriodMinutes,i),iVolume(SymbolName,PeriodMinutes,i),iCustom(SymbolName,PeriodMinutes,"IFT",0,i));

      }

   FileClose(handle);      

//----

   return;

   }

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

//| script program start function                                    |

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

int start()

  {

  int SymbolCounter,PeriodCounter; 

//----

   for (SymbolCounter=1;SymbolCounter<13;SymbolCounter++)

      {

      for (PeriodCounter=2;PeriodCounter<=6;PeriodCounter++)

         {

         //Print("NewBar on ",GetSymbolString(SymbolCounter),PeriodNumber(PeriodCounter),"M");

         IFT_output(GetSymbolString(SymbolCounter),PeriodNumber(PeriodCounter));

         }

      }

   

//----

   return(0);

  }

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

 
kostumer27:

Please help me whith code of export indicators to .csv
It allows write just one indicator...

What should be corrected to export multiple data columns after OHLC ..?

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

//|                                                  RSI_to_File.mq4 |

//|                      Copyright © 2007, MetaQuotes Software Corp. |

//|                                        [url]http://www.metaquotes.ru/[/url] |

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

#property copyright "Copyright © 2007, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.ru/"


#property show_inputs

string SymbolsArray[13]={"","GBPUSD","EURUSD"};


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

//| string SymbolByNumber                                   |

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

string GetSymbolString(int Number)

  {

//----

   string res="";

   res=SymbolsArray[Number];   

//----

   return(res);

  }


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

//| возвращает период                                                |

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

int PeriodNumber(int number)

   {

   int per_min;

   switch (number)

      {

      default: per_min=PERIOD_M1;break;

      case 1: per_min=PERIOD_M5;break;

      case 2: per_min=PERIOD_M12;break;

      }

   return(per_min);   

   }


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

//|   выводит в файл котировки + значения индикатора                 |

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

void IFT_output(string SymbolName,int PeriodMinutes)

   {

   int size=iBars(SymbolName,PeriodMinutes);

//----

   if (size==0) return;

   int handle=FileOpen(SymbolName+PeriodMinutes+"_IFT.csv",FILE_WRITE|FILE_CSV);

   if (handle<0) return;

   FileWrite(handle,"Time seconds;Time;Open;Low;High;Close;Volume;IFT");

   for (int i=size-1;i>=0;i--)

      {

      FileWrite(handle,iTime(SymbolName,PeriodMinutes,i),TimeToStr(iTime(SymbolName,PeriodMinutes,i))

         ,iOpen(SymbolName,PeriodMinutes,i),iLow(SymbolName,PeriodMinutes,i),iHigh(SymbolName,PeriodMinutes,i)

         ,iClose(SymbolName,PeriodMinutes,i),iVolume(SymbolName,PeriodMinutes,i),iCustom(SymbolName,PeriodMinutes,"IFT",0,i));

      }

   FileClose(handle);      

//----

   return;

   }

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

//| script program start function                                    |

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

int start()

  {

  int SymbolCounter,PeriodCounter; 

//----

   for (SymbolCounter=1;SymbolCounter<13;SymbolCounter++)

      {

      for (PeriodCounter=2;PeriodCounter<=6;PeriodCounter++)

         {

         //Print("NewBar on ",GetSymbolString(SymbolCounter),PeriodNumber(PeriodCounter),"M");

         IFT_output(GetSymbolString(SymbolCounter),PeriodNumber(PeriodCounter));

         }

      }

   

//----

   return(0);

  }

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

Just add the data you want to be exported in the FileWrite() function parameters
 
mladen:
As far as I see, that should be correct

I have solve the opposite close function :>

But when you free can you help to check the candle trailing stop , i still cant solve it :(