OrderSend Error 2400 - page 2

 
Tristen Shaw #: OK, first I would like to thank you guys for your time. :)

Second, I have attempted to put your fixes into practice. However, being very new to this, I'm sure I have probably butchered it. I'm struggling to understand some things and am doing my best to try and bumble my way through it. Please don't crucify me lol. I'm currently watching my EA to see what happens when it hits a buy trigger. Edit: As far as the stop loss. I'm eventually trying to use the ZigZag idicator to set the stoploss at a particular low/high. Haven't figured that part out yet.

Unfortunately you did in deed make it worse. Much worse! So, lets start by the definition of things you have neglected to mention. It would be better if you supplied all the code so that we can understand it better. But these are some of the things that to be clarified first.

  1. What do the functions GetSpread() and GetATR() return in value, specifically in what "units"?
    Is it a price range or is it in "points" or in "ticks" or some other unit or scale?
    What is the returning data-type?
    It would be best for you to show their actual code.
  2. What value does "StopLoss" hold?
    What is its "units" or scale, just like in the previous question?
    How is it calculated?
    What is its data-type?
    It would be best for you to show their actual code that calculates it.
Only after you clarify these questions or show all the relevant code, can we proceed to offer you some guidance.
 
Fernando Carreiro #:

Unfortunately you did in deed make it worse. Much worse! So, lets start by the definition of things you have neglected to mention. It would be better if you supplied all the code so that we can understand it better. But these are some of the things that to be clarified first.

  1. What do the functions GetSpread() and GetATR() return in value, specifically in what "units"?
    Is it a price range or is it in "points" or in "ticks" or some other unit or scale?
    What is the returning data-type?
    It would be best for you to show their actual code.
  2. What value does "StopLoss" hold?
    What is its "units" or scale, just like in the previous question?
    How is it calculated?
    What is its data-type?
    It would be best for you to show their actual code that calculates it.
Only after you clarify these questions or show all the relevant code, can we proceed to offer you some guidance.
double GetATR(int i){
   return iATR(_Symbol,PERIOD_CURRENT,AtrPeriod,i);
}

double GetSpread(){
   return MarketInfo(Symbol(), MODE_SPREAD);
}
Stoploss is a place holder. At the moment it holds points which is an input that can be set by the user. Once I get it working, I plan on making a function that identifies the last low using the zigzag indicator and using that to place a stop loss.
 
double BuyStopLoss = NormalizeDouble((Ask-StopLoss-GetSpread())*_Point, Digits);

This still doesn't work.....like 

lets say Ask is 0.7856

StopLoss is 300 points

GetSpread()  == ??

0.7856 - 300  - GetSpread()   ==> very weird number

what I do...if I get something I dont understand, I print...you should print all your calculations so you can check 

double BuyStopLoss = NormalizeDouble((Ask-StopLoss-GetSpread())*_Point, Digits);
Print(BuyStopLoss);

like that

I think it should be like that:

double BuyStopLoss = NormalizeDouble((Ask-(StopLoss*_Point)-GetSpread()), Digits)
 
Tristen Shaw #: Stoploss is a place holder. At the moment it holds points which is an input that can be set by the user. Once I get it working, I plan on making a function that identifies the last low using the zigzag indicator and using that to place a stop loss.

So to recap:

  • "Ask" and "Bid" are "prices"
  • "GetATR()" is a "price range"
  • "StopLoss" is in "points"
  • "GetSpread()" is in "points"
  • Stops Level is also in "points"

So Stops Level, Stop-Loss, and the Spread need to be converted into a "price range" (or alternatively the Spread can just be calculated as "Ask - Bid").

double
   dbSpread        = Ask - Bid,
   dbStopLossRange = _Point * StopLoss,
   dbStopsLevel    = _Point * SymbolInfoInteger( _Symbol, SYMBOL_TRADE_STOPS_LEVEL );

However, this is not sufficient as all the other logic still has many errors, but first lets make sure you understand these points properly before moving on to the others.

EDIT: Also, please note that none of the above require normalisation as all data returned by the system is already normalised.


 
Daniel Cioca #: This still doesn't work.....like lets say Ask is 0.785, StopLoss is 300 point, GetSpread()  == ??

0.7856 - 300  - GetSpread()   ==> very weird number

what I do...if I get something I dont understand, I print...you should print all your calculations so you can check

like that

I think it should be like that:

You are confusing the OP. The Spread returned by MarketInfo is in Points.

Also, don't use the "NormalizeDouble" but instead, use the "tick size" alignment.

 
Daniel Cioca #:

This still doesn't work.....like 

lets say Ask is 0.7856

StopLoss is 300 points

GetSpread()  == ??

0.7856 - 300  - GetSpread()   ==> very weird number

what I do...if I get something I dont understand, I print...you should print all your calculations so you can check 

like that

I think it should be like that:

You indeed have a point.

I am going to do some reworking and post after. I want to show that I am indeed trying to grasp this, not just looking for anyone to do it for me.

 
Fernando Carreiro #:

You are confusing the OP. The Spread returned by MarketInfo is in Points.

Also, don't use the "NormalizeDouble" but instead, use the "tick size" alignment.

Ok, lets see if I'm even moving in the right direction

double GetATR(int i){
   return iATR(_Symbol, PERIOD_CURRENT, AtrPeriod, i);
}

double GetSpread(){
   return _Point*SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
}

//Order Function

void PlaceOrders(){ 
   Print(GetSpread());
   if(GetSpread() < 20 && OrdersTotal() == 0){
      double StopLossRange = _Point*StopLoss;
      double StopLevel = _Point * SymbolInfoInteger( _Symbol, SYMBOL_TRADE_STOPS_LEVEL );      
      if(CurBias == 0){
         double TakeProfitLong = Ask+GetATR(1)+GetSpread()+StopLevel;
         double StopLossLong = Ask-StopLossRange-GetSpread();
         //Place buy order
         int openbuy=OrderSend(_Symbol,OP_BUY,Lots,Ask,1000,Ask-StopLossRange,Ask+TakeProfitLong,"Phoenix Trade",MagicNumber,0,Blue);
      }else{
         //Place sell order
      }      
   }
}

It's not finished, but am I getting warmer?

EDIT: I forgot to change the StopLoss. Working on that now.

EDIT2: Ok, I edited the above code with a new stop loss.

 
Tristen Shaw #: Ok, lets see if I'm even moving in the right direction. It's not finished, but am I getting warmer?

Example code (untested, uncompiled) based on your original source in initial posts:

void PlaceOrder( int nCurBias, double dbLots, int nStopLossPoints, int nSlippage, int nMaxSpread, int nMagicNumber )
{
   int
      nSpread      = (int) SymbolInfoInteger( _Symbol, SYMBOL_SPREAD            ),
      nStopsLevel  = (int) SymbolInfoInteger( _Symbol, SYMBOL_TRADE_STOPS_LEVEL );

   bool bBuy = ( nCurBias      == 0          ) &&
               ( OrdersTotal() == 0          ) &&
               ( nSpread       <  nMaxSpread );
               
   double
      dbAtr             = GetAtr( 1 ),
      dbSpread          = _Point * nSpread,
      dbStopsLevel      = _Point * nStopsLevel,
      dbStopLoss        = _Point * nStopLossPoints,
      dbStopLossRange   = fmax( dbSpread + dbStopLoss, dbStopsLevel ),
      dbTakeProfitRange = fmax( dbSpread + dbAtr     , dbStopsLevel ),
      dbDirection       = bBuy ? +1.0 : -1.0,
      dbPrice           = bBuy ? Ask : Bid,
      dbStopLossPrice   = Round2Ticksize( dbPrice - dbDirection * dbStopLossRange   ),
      dbTakeProfitPrice = Round2Ticksize( dbPrice + dbDirection * dbTakeProfitRange );

   int nTicket = OrderSend( _Symbol, bBuy ? OP_BUY : OP_SELL,
      dbLots, dbPrice, nSlippage, dbStopLossPrice, dbTakeProfitPrice,
      "Phoenix Trade", nMagicNumber, 0, bBuy ? clrBlue : clrMagenta );
      
   if( nTicket > 0 )
   {
      Alert( "Order Fired!" );
   }
   else
   {
      // Something went wrong. Deal with the situation
   };
};
 

Updated example code (untested/uncompiled) based on your latest post:

void PlaceOrder( int nCurBias, double dbLots, int nStopLoss, int nSlippage, int nMaxSpread, int nMagicNumber )
{
   if( OrdersTotal() == 0 )
   {
      int nSpread = (int) SymbolInfoInteger( _Symbol, SYMBOL_SPREAD );
      
      if( nSpread < nMaxSpread )
      {
         bool bBuy = nCurBias == 0;
      
         double
            dbAtr             = GetAtr( 1 ),
            dbSpread          = _Point * nSpread,
            dbStopLoss        = _Point * nStopLoss,
            dbStopsLevel      = _Point * SymbolInfoInteger( _Symbol, SYMBOL_TRADE_STOPS_LEVEL ),
            dbStopLossRange   = fmax( dbSpread + dbStopLoss, dbStopsLevel ),
            dbTakeProfitRange = fmax( dbSpread + dbAtr     , dbStopsLevel ),
            dbDirection       = bBuy ? +1.0 : -1.0,
            dbPrice           = bBuy ? Ask : Bid,
            dbStopLossPrice   = Round2Ticksize( dbPrice - dbDirection * dbStopLossRange   ),
            dbTakeProfitPrice = Round2Ticksize( dbPrice + dbDirection * dbTakeProfitRange );

         int nTicket = OrderSend( _Symbol, bBuy ? OP_BUY : OP_SELL,
            dbLots, dbPrice, nSlippage, dbStopLossPrice, dbTakeProfitPrice,
            "Phoenix Trade", nMagicNumber, 0, bBuy ? clrBlue : clrMagenta );
            
         if( nTicket > 0 )
         {
            Alert( "Order Fired!" );
         }
         else
         {
            // Something went wrong. Deal with the situation
         };
      };
   };
};
 
Fernando Carreiro #:

Example code (untested, uncompiled) based on your original source in initial posts:

lol I take that to mean I was not getting warmer.

Ok, I need some time to dissect and understand this.

Reason: