EA problem with InstaTrader

 

I created an EA for MetaTrader 4, but I have a problem with her on the platform InstaTrader. They open only buy positions. On platforms from other brokers I have met with this problem. Has anyone experience with it? Direction of trade need to generate random. Executing it as follows:

// Vygeneruj smer
   MathSrand(TimeLocal());
   int smer = MathRand();
   
   int type = 0;
   
   if(smer < 16383) 
   {
      type = OP_SELL;   
   }
   else
   {
      type = OP_BUY;
   }
 
So it does not work on InstaTrader but it works everywhere else?
 

On platform from Gallant is ok. Positions are open accidentally.

 

Your version have allot of streaks. Why not use this one instead?

/*
void start(){
    MathSrand(TimeLocal());
    int smer = MathRand();
    int type = 0;
    if(smer < 16383) {
        Alert("Here1================");
        //type = OP_SELL; 
    }
    else
    {
        Alert("Here2================");
        //type = OP_BUY;
    }
}
*/


void start(){
    int Direction=MathRand()%2;
    if(Direction==0){Alert("Here0================");}
    if(Direction==1){Alert("Here1================");}
}
 

Thanks:). But error persists. I find that no matter MetaTrader, but the fact that I am connected to the account instaforex.com. Is there any possibility that it really has influence? It's the same with the demo account and also with a real account.

 
Try doing a simple EA which tries to Sell, and make sure to check for errors with GetLastError() Command.
 

tried to use my old script for sell, error message was not displayed. When I use the same script for buy, is executed. The strange thing is that after using a script to sell - to tens of seconds the server go disconnects. In strategy tab is Error = invalid price..

The script that I used is here..

#include <stdlib.mqh>
#include <WinUser32.mqh>


int start()
  {

  double ProcentoRisku         = 10; //Procento risku vyjádřené v procentech
  double NejvetsiZtrata        = 200; //Největší ztráta v historii (ztráta na obchod, nikoli drowdown)
  double StopLoss              = 0; //StopLoss
  double TakeProfit            = 0; //TakeProfit

  double LotsOptimized = AccountFreeMargin()/100*ProcentoRisku/NejvetsiZtrata;

   if(MessageBox("Opravdu chcete prodat "+LotsOptimized+" lotů  "+Symbol()+" za BID cenu?    ",
                 "Script",MB_YESNO|MB_ICONQUESTION)!=IDYES) return(1);

   int ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized,Ask,3,StopLoss,TakeProfit,"expert comment",255,0,CLR_NONE);
   if(ticket<1)
     {
      int error=GetLastError();
      Print("Error = ",ErrorDescription(error));
      return;
     }

   OrderPrint();
   return(0);
  }
 
Sell at Bid, Buy at Ask
Reason: