Opening positions after X amount of points from bar opening - page 2

 
Subgenius:

pseudo-code should envelope all variables in the equation and yours seems illogical because its possibly missing some information.

your intention is to open orders when price is greater or lesser than current bar open price, so what is compared?

bar zero open price &

Subgenius:

pseudo-code should envelope all variables in the equation and yours seems illogical because its possibly missing some information.

your intention is to open orders when price is greater or lesser than current bar open price, so what is compared?

bar zero open price & what?

Bar opening price plus or minus 150 points.

  // Buy Order 
                if(Ask – Open[0] > 150/1000) {




         // Sell Order 
        if (Open[0]-Bid > 150/1000)
                        {
                      

 

 
patrick007:
Does that work on EURUSD ?
 
RaptorUK:
Does that work on EURUSD ?

It opens orders, but not after 150 point change. I can't suss out what it is doing other than going bust. I just want to get the EA together to see if there is any profit to be made from large movements in 1 minute. Obviously, it would apply to other currencies also, as these movements tend to be mirrored. It would not trade often and a trailing stop loss would be essential. I will keep at it. Thanks.
 
RaptorUK:
Nope . . .  perhaps you mean 150 points ?

Wasn't this a big enough hint ?
 
RaptorUK:
Wasn't this a big enough hint ?
I am not PC Plod and I am bad at cluedo and even worse at pseudo. Whether 15/100 or 150/1000 it isn't functioning correctly. It opens orders on the first bar irrespective of change from opening price. Thanks.
 
patrick007:

I am not PC Plod and I am bad at cluedo and even worse at pseudo. Whether 15/100 or 150/1000 it isn't functioning correctly. It opens orders on the first bar irrespective of change from opening price. Thanks.
So why not use what you actually mean to code in the first place . . .  what does 150/100 or 150/1000 mean ?  why not use 150 * Point ?
 
RaptorUK:
So why not use what you actually mean to code in the first place . . .  what does 150/100 or 150/1000 mean ?  why not use 150 * Point ?

Thank you. Will try.
 

Apart from the obvious comments like "give up, Son", this won't open orders. The order close error 4051 appears in the journal. Is the open order illogical too?

extern int startTradingHour = 4;
extern int endTradingHour = 19;
extern double lotSize = 0.1;
extern int maxTrades = 1;
extern int magicNumber = 1;
extern double StopLossPoints = 40;
extern double TakeProfitPoints = 600;
extern double TrailingStopLoss1 = 40;
extern double TrailingStopLoss2 = 100;
extern bool CheckOncePerBar = false;
extern double askpointFact = 150;
extern double bidpointFact = -150;
datetime lastTrade;


 
int start() {
 
 
 
 
 // check Trading hours
   if (Hour() < startTradingHour || Hour() > endTradingHour) {
   
      if (OrderType() == OP_BUY) {
         OrderClose( OrderTicket(), OrderLots(),OrderSymbol(),Red);
      lastTrade = Time [0]; 
         return(0);
      } else if (OrderType() == OP_SELL) {
         OrderClose( OrderTicket(), OrderLots(),OrderSymbol(),Red);
        lastTrade = Time [0];  
         return(0);
      } 
     
   if (CheckOncePerBar == true){
   
   int BarShift = 1;
   bool NewBar = true;
   }
   else NewBar = false;
   }
   else {
   NewBar = true;
   BarShift = 0;         
   lastTrade = Time[0];
   
      
   //Market Order Opening Criteria
     
     double price;
     double StopLoss;
     double TakeProfit;
     double pointFact; 
     
    
     if(Ask >= Open[0]+ pointFact){
         return(true);
     }
     
     if(Bid <= Open[0]- pointFact){
         return(true);
     } else {
         return(false);
     }
      
    //Order sending
    
      if(price == Bid -pointFact *Point) {
         StopLoss = price + (StopLossPoints * Point);
         TakeProfit = price - (TakeProfitPoints * Point);
      }
      if (Bid + Open[0] >= 150 *Point) {
         OrderSend(Symbol(), OP_SELL, lotSize, price,Bid,3,StopLoss,TakeProfit,0,"Sell Order", magicNumber);
         lastTrade = Time[0];
         return(0);
         }
         if (OrderType() == OP_SELL)
          StopLoss = price + (StopLossPoints * Point);
           TakeProfit = price - (TakeProfitPoints * Point); {
         OrderClose( OrderTicket(), OrderLots(),OrderSymbol(),Red);  
         return(0);
      }
         
                 
        if (price == Ask + pointFact *Point) {
         StopLoss = price - (StopLossPoints * Point);
          TakeProfit = price + (TakeProfitPoints * Point);
      }
      if(Ask - Open[0] >= 150 *Point ) {
         OrderSend(Symbol(), OP_BUY, lotSize, price,Ask,3,StopLoss,TakeProfit,0,"Buy Order", magicNumber);
         lastTrade = Time[0];
         return(0);
      }
       if (OrderType() == OP_BUY)
       StopLoss = price - (StopLossPoints * Point);
          TakeProfit = price + (TakeProfitPoints * Point);{ 
         OrderClose( OrderTicket(), OrderLots(),OrderSymbol(),Red); 
         return(0);
      }
             
              
      //trailing stops
      
    
      if (OrderType() == OP_BUY && OrderProfit()>60 *Point) { 
         OrderModify(OrderTicket(), OrderLots(), TrailingStopLoss1, OrderTakeProfit(), OrderExpiration());
         return(0);
      } else if (OrderType() == OP_SELL && OrderProfit()>60 *Point) { 
         OrderModify(OrderTicket(), OrderLots(), TrailingStopLoss1, OrderTakeProfit(), OrderExpiration());
         return(0);
      }
      
    
      
      if (OrderType() == OP_BUY && OrderProfit()>120  *Point) {
         OrderModify(OrderTicket(), OrderLots(), TrailingStopLoss2, OrderTakeProfit(), OrderExpiration());
         return(0);
      } else if (OrderType() == OP_SELL && OrderProfit()>120 *Point) {
         OrderModify(OrderTicket(), OrderLots(), TrailingStopLoss2, OrderTakeProfit(), OrderExpiration());
         return(0);
      }
   }
}
 
      
 
patrick007:

Apart from the obvious comments like "give up, Son", this won't open orders. The order close error 4051 appears in the journal. Is the open order illogical too?

When you have problems with a function you need to check you are using it correctly,  have you checked ?  have you read the documentation ?  OK you haven't,  but why not ?  it would take you 2 minutes . . .  instead you wait for a reply,  I don't mind helping but you can help yourself much, much quicker and learn in the act of doing so . . .

Take one of your OrderClose() calls . . .

OrderClose( OrderTicket(), OrderLots(), OrderSymbol(),Red);

 now read the documentation:  click the links here  OrderTicket()  OrderLots()  OrderSymbol()    there is very little to read about these three functions,  this is what they have in common  

"Note: The order must be previously selected by the OrderSelect() function."

 . . .   where is your OrderSelect() call to select the order that you want to know the   Ticket Number,  Position Size and Symbol for ? 

 

Why does your OrderSend() fail ?   What are Function return values ? How do I use them ?

You OP_BUY at Ask,  no other price,  you OP_SELL at Bid,  no other price.   Read the documentation:  OrderSend()  you are trying to buy at   Ask + pointFact *Point

 
RaptorUK:

When you have problems with a function you need to check you are using it correctly,  have you checked ?  have you read the documentation ?  OK you haven't,  but why not ?  it would take you 2 minutes . . .  instead you wait for a reply,  I don't mind helping but you can help yourself much, much quicker and learn in the act of doing so . . .

Take one of your OrderClose() calls . . .

 now read the documentation:  click the links here  OrderTicket()  OrderLots()  OrderSymbol()    there is very little to read about these three functions,  this is what they have in common  

"Note: The order must be previously selected by the OrderSelect() function."

 . . .   where is your OrderSelect() call to select the order that you want to know the   Ticket Number,  Position Size and Symbol for ? 

 

Why does your OrderSend() fail ?   What are Function return values ? How do I use them ?

You OP_BUY at Ask,  no other price,  you OP_SELL at Bid,  no other price.   Read the documentation:  OrderSend()  you are trying to buy at   Ask + pointFact *Point

 

Thank you for your reply. All very helpful.

 

Reason: