[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 195

 

Please help with two simple scripts which open

pending orders to buy and sell with set stoploss and takeprofit at given

Distance from current price. I miraculously wrote one that works.

I accidentally deleted it and now I can't remember what I did to make it work.

only hope for you...

sell:


int start()
{
OrderSend(Symbol(),OP_SELLSTOP,0.01,Bid-20*Point,3,Bid+50*Point,Bid-50*Point);

return(0);
}


and buy


int start()

{
OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+20*Point,3,Bid+50*Point,Bid-50*Point);

return(0);
}

help please...

 
NickXXX:

Hi all!

Today I'm exercising with time) For example, I need to make an indicator do something at a certain time.

The code will be as follows:

Now, let's say we want our condition to work not only at 21.30, but also at 22.00, 22.30, 23.00, and so on...

You can, of course, do the following:

But I think it's somehow irrational, especially if there will be a lot of checkpoints. I think you can and simpler.

Question, how to make it easier (right) ?)

Here, it depends on whether the time conditions follow a law or a pattern. For example for your case, every half hour: if(TimeCurrent()%1800==0) {tra-ta}. If there is no logic in these time points - your option. Only I don't like it, it's a strict equality, if there's no tick in this minute - EA will miss the condition...
 
Figar0:
Here it all depends on whether the time conditions are subject to any law, whether there is a pattern or not. For example, for your case, every half hour: if (TimeCurrent()%1800==0) {tra-ta}. If there is no logic in these time points - your option. Only I don't like it, it's a strict equality, if there is no tick in this minute - EA will miss the condition...

I.e. checking for the remainder of the division works. But it seems to me that in this case there will always be a remainder...

I completely agree with strict equality, I haven't thought it through yet. In principle, you could probably do something like an interval, such as 16.00 - 16.03.

But the point was just to make it once every half an hour to do calculations and go to sleep. So that the system is not constantly burdened with unnecessary calculations.

 
NickXXX:

I.e. checking for the remainder of the division works. But it seems to me that in this case there will always be a remainder...


Yes, you're right, it's better: if(TimeCurrent()%1800<60) {tra-ta}.
 
Figar0:

Well yes, you're right, better like this: if (TimeCurrent()%1800<60) {tra-ta}.

< 0.6, or something else like that. The remainder of division is always less than one :)
 

What if there are a lot of variables like that?

double Time_Mes_1=21.30;
double Time_Mes_2=22.00;
double Time_Mes_3=22.30;
...

Is that too bad, or will it work?

And another small question, if say I set an interval (e.g. 16.00-16.03) for a condition to be executed. How to make it execute it only once, despite arrival of new ticks???

 

1. There is a data type: datetime. If you want something exotic, you can use int for time, but double is an extreme case.

2. go back 5-10 pages: it says how to do what you want.

 

Hello.

Please help me to correct the code.

Both lines below are glitchy.

Thanks in advance.

if((OrderMagicNumber()==MAGIC || OrderMagicNumber()==777))

if((OrderMagicNumber()==(MAGIC || 777))

The program itself:

int OrdTicket_b()
 {
  string SMB=Symbol();
  int OrdTicket;
  int MAGIC;
  int i;
  for (i=0; i<OrdersHistoryTotal(); i++)
   {
    if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)
     {
      if(OrderSymbol()==SMB)
       {
        if(OrderMagicNumber()==MAGIC || OrderMagicNumber()==777)
         {
          if(OrderType()==OP_BUY || OrderType()==OP_SELL)
           {
            OrdTicket=OrderTicket();
           }  
         }  
       }          
     }
   }
  return(OrdTicket);
 }
 
tara:
Please don't spread heresy in public. Go nerd out somewhere else, there's plenty to go around...
 
tara:

1. There is a data type: datetime. If you want something exotic, you can use int for time, but double is an extreme case.

If you want to use time, you must use int and double. 2) Rewind 5-10 pages backwards: it's written there how to do what you want.

1. Well, here double was only used to add minutes and hours, so that you could mark checkpoints as HH.MM (e.g. 16. 23).

2. Looked at the last pages, of course there is about datetime, but not exactly the same. They simply output in HH.MM format the time of the last order.


Reason: