[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 1124

 

Good afternoon. Back to my question. The reverse transaction does not work. Looked around the site but didn't find anything on this topic. Can you advise what I'm doing wrong (still learning the language). It is required to be triggered on a single candle.

extern double TP = 70; //takeprofit
extern double SL = 0; //stoploss
extern double Lot = 0.1;

double HighLevel;
double LowLevel;
int resBuy=0;
int resSell=0;


//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
HighLevel=High[1];
LowLevel=Low[1];
return;
}

//+------------------------------------------------------------------+
//| expert function |
//+------------------------------------------------------------------+

void start()
{

if(Bars<100 && IsTradeAllowed()==false) return;


if(resBuy==0 && resSell==0 && CheckBreak()==-1)
{
resSell=OrderSend(Symbol(),OP_SELL,Lot,Bid,2,0,Bid -TP,"",MAGICMA,0,Red);
HighLevel=LowLevel;
LowLevel=Close[1];
return;
}

if(resBuy==0 && resSell==0 && CheckBreak()==1)
{
resBuy=OrderSend(Symbol(),OP_BUY,Lot,Ask,2,0,Ask + TP,"",MAGICMA,0,Blue);
LowLevel=HighLevel;
HighLevel=Close[1];
return;
}

if(resBuy!=0 && resSell==0 && Close[1]<LowLevel) //------------------------------------- interested in this part: closing and opening on one bar
{
bool closeBuy=OrderClose(resBuy, Lot, Bid, 2, Blue);
// while(!IsTradeAllowed()) Sleep(100);
resSell=OrderSend(Symbol(),OP_SELL,Lot,Bid,2,0,Bid -TP,"",MAGICMA,0,Red);
HighLevel=LowLevel;
LowLevel=Close[1];
return;
}

if(resSell!=0 && resBuy==0 && Close[1]>HighLevel) //------------------------------------- interested in this part: closing and opening on one bar
{
bool closeSell=OrderClose(resSell, Lot, Ask, 0.0002, Red);
// while(!IsTradeAllowed()) Sleep(100);
resBuy=OrderSend(Symbol(),OP_BUY,Lot,Ask,2,0,Ask + TP,"",MAGICMA,0,Blue);
LowLevel=HighLevel;
HighLevel=Close[1];
return;
}

}

//----------------------------------------------------------------- Check Low&High break (Func)

double CheckBreak()
{
double candle=Open[1]-Close[1];

if(candle>0 && Low[1]<LowLevel) return(-1);
if(candle<0 && High[1]>HighLevel) return(1);
}


 
Good day all,

There is a problem with arrays:

Suppose

int start (){ // Function start

int OrdSen_1=OrderSend(Symbol(), OP_BUY, 0.10, Ask,1, Ask-70*Point, Ask+70*Point); // Buy order
if(OrdSen_1==-1){ Alert("OrdSen_1 ",GetLastError());} // Checking for an error when placing an order

double mas1[]={}; // Array
}

The question is how to place the values "Symbol(), OP_BUY, 0.10, Ask,1, Ask-70*Point, Ask+70*Point" that belong to OrdSen_1 into the array mas1[]={}, so they can be further used, taken from the array or equate these values with variables for their further use. There may be more such orders, as well as arrays. The main thing is to understand the principle.

VERY grateful for help and explanations, preferably in detail :)
 
Techno:

Outside will be deleted because you don't use it, i.e. you don't call it from anywhere, is that clear now?

Got it, thanks :)
 
artmedia70:

What do you think of this sample? :)))))

With wifi, it's OK.
 

Greetings. How can the editor keep track of all the places in code where the same variable. function is used?

 
Galion:

Greetings. How can the editor keep track of all the places in code where the same variable. function is used?


I use Notepad++ for this. All you have to do is highlight a variable once, so it's highlighted throughout your code.

 
But for Notepad++ to highlight syntax, you need to tune it to MQL4 language. Type Notepad++ in this forum's search and you will find a link to an already configured editor - I've posted it here more than once.
 
drknn:
But for Notepad++ to highlight syntax, you need to tune it to MQL4 language. Type Notepad++ in this forum's search and you will find a link to an already configured editor - I've posted it here more than once.

Thank you. Installed it, it lights up, it's more fun))
 
Galion:

Thank you. Installed it, it lights up, it's more fun))

There's a very interesting function to mark found variables. Press Ctrl+F, enter variable name, check "Bookmark" and "Mark found". Then press the "Find all" button. To remove this, press the "Remove all" button
 
drknn:

There is a very interesting function for marking found variables. Press Ctrl+F, enter a variable name, tick the "Bookmark" and "Mark found" boxes. Then press the "Find all" button. To remove this click "Remove all".

And double click goes to code snippet))) Just what I need, thanks)