need guide in this trading operation

 
int ticket;
   if (allsignal==1 && total<3 && enableopen==true)                                                       //condition allsignal is alligator signal,total=orderstotal()<
      {
      ticket=OrderSend(Symbol(),OP_BUY,lotsize,Ask,slippage,0,0,"Order #2",NULL,Magic,Green);  //entry market buy
      if(ticket<0)
         {
         Print("OrderSend failed with error #",GetLastError());
         return(0);
         }
      }
   else if(allsignal==2 && total<3 && enableopen==true)                                                       //condition 
      {
      ticket=OrderSend(Symbol(),OP_SELL,lotsize,Bid,slippage,0,0,"Order #2",NULL,Magic,Red);  //entry market sell
      if(ticket<0)
         {
         Print("OrderSend failed with error #",GetLastError());
         return(0);
         }
      }
   else Print("No signal");

 question:

1. this is my current market entry code, is there anyway to improve this one?

 2. how can i make this code to only enter one time for each signal happen?

for (int i=1; i<=OrdersTotal(); i++)            //Cycle for all orders..
     {                                          
      if(OrdersTotal()>0)
         {
         if(OrderSelect(i-1,SELECT_BY_POS)==true)  
            {                                     
            OrderModify(i, OrderOpenPrice(), OrderOpenPrice()-0.002,OrderOpenPrice()+0.004,0,CLR_NONE);
            }
         }
     }                                              

 3. after entering the above, the ea only execute 6 trade with hundreds of signal, why will this happen?

4. and then there is lots of  error 4108 after testing this code.why?

 

Would you please not double posting everywhere !. I have to delete your other topic because you're asking the same exact question.

www.google.com/search?q=site:https://forum.mql4.com/ one trade per bar 

 

shenlongming,

Please express your thoughts as to what objective your EA is intended to accomplish?

Thank you.

 

sorry for the double posting

well first, my ea include the following

signal alligator signal,which i had done

ao signal,done

fractal signal(i cant make it to work)

entry open a trade  when any of the indicator give signal (one order per signal,and one signal per bar for each indicator)

i'm stuck here

close close all order with given take profit and stoploss

moving average trailing stop  

 that's all, will you please guide me in making this?

Files:
anthony.mq4  10 kb
 

This is the moment when WHRoder is supposed to type his famous "there are no slaves here, learn to code or pay someone" statement.

I will be searching for his statement to pop up on this page tomorrow.

I can't type it out for you, but if you are willing to code it one step at a time, I do not mind providing assistance, in fact, I welcome it. I simply can't spare enough time to type it out for you.

I am sure you understand and are willing to code the majority of it yourself.

I'll have a look at your code if you wish.

Thank you.

 
WhooDoo22:


This is the moment when WHRoder is supposed to type his famous "there are no slaves here, learn to code or pay someone" statement.

I will be searching for his statement to pop up on this page tomorrow.

I can't type it out for you, but if you are willing to code it one step at a time, I do not mind providing assistance, in fact, I welcome it. I simply can't spare enough time to type it out for you.

I am sure you understand and are willing to code the majority of it yourself.

I'll have a look at your code if you wish.

Thank you.


i know and i choose to code it myself, now the problem is, i'm stuck in the fractal section and trading section, any article or guide for me to do it?

and yes, i need your assistance please.my question now are

1. how to limit to one trade per signal per bar.

2. how to use fractal indicators to trade? i mean can the terminal store the previous fractal by itself ?only the latest 2 is needed(one buy one sell)

3. i kept getting error 4108 when testing the code, what this mean?or should i change the  orderselect code?

that's all for now 

 

shenlongming,

1. how to limit to one trade per signal per bar.

orderselect() function
if(OrdersTotal()<1){

2. how to use fractal indicators to trade? i mean can the terminal store the previous fractal by itself ?only the latest 2 is needed(one buy one sell)

Use the fractal patterns I provided for ordersend parameters-

// upper fractal pattern

   if((High[2]>High[1])&&(High[2]>High[3])&&(High[2]>High[0])&&(High[2]>High[4])){ ordersend. }

// lower fractal pattern

   if((Low[2]<Low[1])&&(Low[2]<Low[3])&&(Low[2]<Low[0])&&(Low[2]<Low[4])){ ordersend. }

3. i kept getting error 4108 when testing the code, what this mean?or should i change the  orderselect code?

I believe the reason your mt4 journal is reading "error 4108" is because your orderclose function is constantly searching for the order to close OR your ordersend parameters are creating this error-

(orderclose or ordersend parameters = "error 4108").

orderselect() function
if(OrdersTotal()<1){

Thank you.

 

one question, how to make indicators to calculate one time only for each bar and not with tick, so i get one signal per bar?

thanks

 
Always count down in your orderSelect loops. Loops and Closing or Deleting Orders - MQL4 forum
 

Perhaps try implementing this :

 //execute on bar open
          if(CheckOncePerBar == true)
             {
              int BarShift = 1;
              if(CurrentTimeStamp != Time[0])
                 { 
                  CurrentTimeStamp = Time[0];
                  bool NewBar = true;
                 }
              else NewBar = false;
             }
          else 
             {
              NewBar = true;
              BarShift = 0;
             }
       //-----------------------      
          if(NewBar==true) 
             {
              // SIGNAL & ORDERS
u need to add global variable -
datetime CurrentTimeStamp;

and add:

int init()
  {
      
   CurrentTimeStamp = Time[0];
   
  }

 variable :

extern bool CheckOncePerBar = true;

 to switch this on or off.

As I am newbie in programmig I might be wrong :) but good luck.

 

i will try sirru code, thx  a lot

 right now my ea is working, but still a few more modification is needed

1st, how to solve error 130/145/1, my entry and out code is as follow.

//entry
int ticket;
   if (buysignal==1 && total<maxorders && enableopen==true)                                                       	//condition 
      {
//string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
      ticket=OrderSend(Symbol(),OP_BUY,lotsize,Ask,slippage,0,0,"Order #2",NULL,Magic,Green);  				//entry market buy
      if(ticket<0)
         {
         Print("OrderSend failed with error #",GetLastError());
         buysignal=0;
         return(0);
         }
      }
   else if(sellsignal==2 && total<maxorders && enableopen==true)                                                       	//condition 
      {
      ticket=OrderSend(Symbol(),OP_SELL,lotsize,Bid,slippage,0,0,"Order #2",NULL,Magic,Red);  				//entry market sell
      if(ticket<0)
         {
         Print("OrderSend failed with error #",GetLastError());
         sellsignal=0;
         return(0);
         }
      }
//closing
for(int i=0;i<total;i++)
   {
   if(!(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)))continue;
      {
      if(close1<teeth && OrderType()==OP_BUY)
         {            {
         OrderModify(OrderTicket(),OrderOpenPrice(),jaw,OrderTakeProfit(),0,CLR_NONE);
         }
      if(close1>teeth && OrderType()==OP_SELL)
         {
         OrderModify(OrderTicket(),OrderOpenPrice(),jaw,OrderTakeProfit(),0,CLR_NONE);
         }
      }
   }

2. i wonder why my close sometimes work perfectly but sometimes dont, i made it to close all order whenever the price is below the alligator jaw value,when tested, some do exactly as i coded, but some simply dont, why?

i should say it might delay a long time before get out 

3. how to store the fractal value and then erase it whenever a new value occur, can you show me or link me to the tutorial?