Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1833

 
Tretyakov Rostyslav #:
How are the first orders placed?
if(Close[1]>Open[1] && CountOrders()==0)
               if(NewsSellAllow == true)
                  ticket2 = OrderSend(Symbol(),OP_SELLSTOP, LotSk, Bid-(Skachok*Point), Slippage, 0, Bid-((Skachok+TPsk)*Point), "открыт ордер на продажу", Magic, 0, Red);
                  Print("OpenOrderSuccess");
                  
            if(Close[1]>Open[1] && CountOrders()==0)
               if(NewsBuyAllow == true)
                  ticket2 = OrderSend(Symbol(),OP_BUYSTOP, LotSk, Ask+(Skachok*Point), Slippage, 0, Ask+((Skachok+TPsk)*Point), "открыт ордер на покупку", Magic, 0, Blue);
                  Print("OpenOrderSuccess");
 
Порт-моне тв #:
Let me have a look.
 
Порт-моне тв #:
You have the same condition for both order types
if(Close[1]>Open[1] && CountOrders()==0)
 
Tretyakov Rostyslav #:
You have the same condition for both order types

is that how I want it, both ways, or do I need to add something?

 
Порт-моне тв #:

is that how I want it, both ways, or do I need to add something?

Here...modification once at bar opening

As for the opening, if you trade on the news, then "Close[1]>Open[1]" is not needed at all.

on one side "Close[1]>Open[1]", and on the other side "Close[1]<Open[1]".

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Close[1]>Open[1] && CountOrders()==0)
     {
      if(NewsSellAllow == true)
        {
         ticket2 = OrderSend(Symbol(),OP_SELLSTOP, LotSk, Bid-(Skachok*Point), Slippage, 0, Bid-((Skachok+TPsk)*Point), "открыт ордер на продажу", Magic, 0, Red);
         Print("OpenOrderSuccess");
        }
     }
   if(Close[1]>Open[1] && CountOrders()==0)
     {
      if(NewsBuyAllow == true)
        {
         ticket2 = OrderSend(Symbol(),OP_BUYSTOP, LotSk, Ask+(Skachok*Point), Slippage, 0, Ask+((Skachok+TPsk)*Point), "открыт ордер на покупку", Magic, 0, Blue);
         Print("OpenOrderSuccess");
        }
     }
   if(newbar!=Time[0])
     {
      ModifyOrder();
      newbar=Time[0];
     }
  }
//+------------------------------------------------------------------+
//| Подсчет открытых ордеров                                         |
//+------------------------------------------------------------------+
int CountOrders(int ot=-1) 
  {
   int cnt=0;
   int i=OrdersTotal()-1;
   for(int pos=i;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol&&OrderMagicNumber()==Magic)
           {
            if(OrderType()==ot||ot==-1) cnt++;
           }
        }
     }
   return(cnt);
  }
//+------------------------------------------------------------------+
//| Модификация ордера                                               |
//+------------------------------------------------------------------+
void ModifyOrder()
  {
   int i=OrdersTotal()-1;
   for(int pos=i;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==_Symbol&&OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUYSTOP&&OrderOpenPrice()!=Ask+(Skachok*Point))
              {
               if(OrderModify(OrderTicket(), Ask+(Skachok*Point), 0, Ask+((Skachok+TPsk)*Point)))
                 {Print("Ордер модифицирован");}
               else
                 {Print("Ошибка модификации ордера:", GetLastError());}
              }
            if(OrderType()==OP_SELLSTOP&&OrderOpenPrice()!=Bid-(Skachok*Point))
              {
               if(OrderModify(OrderTicket(), Bid-(Skachok*Point), 0, Bid-((Skachok+TPsk)*Point)))
                 {Print("Ордер модифицирован");}
               else
                 {Print("Ошибка модификации ордера:", GetLastError());}
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
 
Tretyakov Rostyslav #:

Here...modification once at bar opening

As for the opening, if you trade on the news, then "Close[1]>Open[1]" is not needed at all, and if the candle has a value, then

on one side "Close[1]>Open[1]", and on the other side "Close[1]<Open[1]".

Thank you, I will try it tomorrow morning.

 

Greetings. Can you please tell me how to connect an EA to a dll in C# ?

I am creating an application and a library

From the application works

EA

#property strict

#import "C:\Users\Андрей\source\repos\ConsoleAppForMql\ClassLibraryForMql\bin\Debug\ClassLibraryForMql.dll"
void Method();
#import

int OnInit(){

Print("  до вызова Method()");
Method();


return(INIT_SUCCEEDED);}

void OnDeinit(const int reason){

}
void OnTick(){

}

Outputs

I assume it can't find Method() as it's inside ClassForMql class, but it's not clear how to specify it.

 
Andrey Sokolov #:

Greetings. Could you please tell me how to connect an EA to a dll in C# ?

If it's MT4 then "chew" the articlehttps://www.mql5.com/ru/articles/249

You are waiting for a fascinating journey into the world of uncontrolled exports )))


If it's MT5, start with a little, first connect the test code from Metaquothttps://www.mql5.com/ru/forum/285631

 
Igor Makanu #:

if this is MT4 then "chew on" the articlehttps://www.mql5.com/ru/articles/249

You are in for a fascinating journey into the world of unmanaged exports )))


If it's MT5, start small, first connect the test code from Metacquothttps://www.mql5.com/ru/forum/285631

If so, then 5. 4 will also be needed, but later.

 
Igor Makanu #:

A fascinating journey into the world of uncontrollable exports awaits you ))))

It has indeed been very exciting)))