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

 
001:

I can't understand the logic of the compiler. I have a function. I declare an external variable.

int start;

further the function body

double B()
{

int i=0, k=OrdersHistoryTotal();
for (i=k-1; i<=k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)!=false) {
if(OrderType()==OP_SELL) {
if(OrderProfit()< 0) {start=1;}

}

}

}

}

The value of the start variable must be memorized and equated with zero when needed. But in this case, if OrderProfit()<0 , then start=1, and if OrderProfit()> 0 , then automatically start=0.

no

if OrderProfit()> 0, the variable will store the same value

 
Tantrik:
Can you tell me where to find it? It's all in English.
If you are not able to set MetaEditor to Russian, use the link Documentation
 
ilunga:

no

If OrderProfit()> 0, what was in the variable remains


Here is the function .

//+------------------------------------------------------------------+
double Balans()
{

int i=0, k=OrdersHistoryTotal();
for (i=k-1; i<=k; i++) {
//------------------------------------------------------------
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)!=false) {
if (OrderType()==OP_SELL) {
if(OrderProfit()<0) {start=true;}
}
}

//-----------------------------------------------------------
}
Print(" start= ",start);
if(lots<0.01) lots=0.01;
lots=NormalizeDouble(lots,2);
return(lots);
}
//+------------------------------------------------------------------+

Here is the log.

16:01:36 2007.07.12 00:01 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.12 00:01 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.12 00:01 Bars_Trader GBPUSD,M1: open #1 sell 0.01 GBPUSD at 2.03190 tp: 2.03100 ok
16:01:36 2007.07.12 04:01 Bars_Trader GBPUSD,M1: close #1 sell 0.01 GBPUSD at 2.03190 tp: 2.03100 at price 2.03210
16:01:36 2007.07.07.13 04:04 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.13 04:04 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.13 04:04 Bars_Trader GBPUSD,M1: open #2 sell 0.01 GBPUSD at 2.02860 tp: 2.02770 ok
16:01:36 2007.07.13 08:00 Bars_Trader GBPUSD,M1: close #2 sell 0.01 GBPUSD at 2.02860 tp: 2.02770 at price 2.02890
16:01:36 2007.07.07.16 20:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.16 20:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.16 20:00 Bars_Trader GBPUSD,M1: open #3 sell 0.01 GBPUSD at 2.03640 tp: 2.03550 ok
16:01:36 2007.07.17 00:05 Bars_Trader GBPUSD,M1: close #3 sell 0.01 GBPUSD at 2.03640 tp: 2.03550 at price 2.03630
16:01:36 2007.07.18 16:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.18 16:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.18 16:00 Bars_Trader GBPUSD,M1: open #4 sell 0.01 GBPUSD at 2.04880 tp: 2.04790 ok
16:01:36 2007.07.18 20:00 Bars_Trader GBPUSD,M1: close #4 sell 0.01 GBPUSD at 2.04880 tp: 2.04790 at price 2.05430
16:01:36 2007.07.19 04:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 04:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 04:00 Bars_Trader GBPUSD,M1: open #5 sell 0.01 GBPUSD at 2.05140 tp: 2.05050 ok
16:01:36 2007.07.19 08:00 Bars_Trader GBPUSD,M1: close #5 sell 0.01 GBPUSD at 2.05140 tp: 2.05050 at price 2.05200
16:01:36 2007.07.19 16:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 16:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 16:00 Bars_Trader GBPUSD,M1: open #6 sell 0.01 GBPUSD at 2.04840 tp: 2.04750 ok
16:01:36 2007.07.19 17:33 Tester: take profit #6 at 2.04750 (2.04760 / 2.04790)
16:01:36 2007.07.20 04:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.20 04:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.20 04:00 Bars_Trader GBPUSD,M1: open #7 sell 0.01 GBPUSD at 2.04810 tp: 2.04720 ok
16:01:36 2007.07.20 08:00 Bars_Trader GBPUSD,M1: close #7 sell 0.01 GBPUSD at 2.04810 tp: 2.04720 at price 2.04900
16:01:36 2007.07.25 00:00 Bars_Trader GBPUSD,M1: start=1
16:01:36 2007.07.25 00:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.25 00:00 Bars_Trader GBPUSD,M1: open #8 sell 0.01 GBPUSD at 2.06160 tp: 2.06070 ok
16:01:36 2007.07.25 02:12 Tester: take profit #8 at 2.06070 (2.06040 / 2.06070)
16:01:36 2007.07.26 08:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.26 08:00 Bars_Trader GBPUSD,M1: start= 0

 
001:


Here is the function .

//+------------------------------------------------------------------+
double Balans()
{

int i=0, k=OrdersHistoryTotal();
for (i=k-1; i<=k; i++) {
//------------------------------------------------------------
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)!=false) {
if(OrderType()==OP_SELL) {
if(OrderProfit()<0) {start=true;}
}
}

//-----------------------------------------------------------
}
Print(" start= ",start);
if(lots<0.01) lots=0.01;
lots=NormalizeDouble(lots,2);
return(lots);
}
//+------------------------------------------------------------------+

Here's the log.

16:01:36 2007.07.12 00:01 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.12 00:01 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.12 00:01 Bars_Trader GBPUSD,M1: open #1 sell 0.01 GBPUSD at 2.03190 tp: 2.03100 ok
16:01:36 2007.07.12 04:01 Bars_Trader GBPUSD,M1: close #1 sell 0.01 GBPUSD at 2.03190 tp: 2.03100 at price 2.03210
16:01:36 2007.07.13 04:04 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.13 04:04 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.13 16:04 Bars_Trader GBPUSD,M1: open #2 sell 0.01 GBPUSD at 2.02860 tp: 2.02770 ok
16:01:36 2007.07.13 08:00 Bars_Trader GBPUSD,M1: close #2 sell 0.01 GBPUSD at 2.02860 tp: 2.02770 at price 2.02890
16:01:36 2007.07.16 20:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.16 20:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.16 20:00 Bars_Trader GBPUSD,M1: open #3 sell 0.01 GBPUSD at 2.03640 tp: 2.03550 ok
16:01:36 2007.07.17 00:05 Bars_Trader GBPUSD,M1: close #3 sell 0.01 GBPUSD at 2.03640 tp: 2.03550 at price 2.03630
16:01:36 2007.07.18 16:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.18 16:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.18 16:00 Bars_Trader GBPUSD,M1: open #4 sell 0.01 GBPUSD at 2.04880 tp: 2.04790 ok
16:01:36 2007.07.18 20:00 Bars_Trader GBPUSD,M1: close #4 sell 0.01 GBPUSD at 2.04880 tp: 2.04790 at price 2.05430
16:01:36 2007.07.19 04:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 04:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 04:00 Bars_Trader GBPUSD,M1: open #5 sell 0.01 GBPUSD at 2.05140 tp: 2.05050 ok
16:01:36 2007.07.19 08:00 Bars_Trader GBPUSD,M1: close #5 sell 0.01 GBPUSD at 2.05140 tp: 2.05050 at price 2.05200
16:01:36 2007.07.19 16:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 16:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.19 16:00 Bars_Trader GBPUSD,M1: open #6 sell 0.01 GBPUSD at 2.04840 tp: 2.04750 ok
16:01:36 2007.07.19 17:33 Tester: take profit #6 at 2.04750 (2.04760 / 2.04790)
16:01:36 2007.07.20 04:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.20 04:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.20 04:00 Bars_Trader GBPUSD,M1: open #7 sell 0.01 GBPUSD at 2.04810 tp: 2.04720 ok
16:01:36 2007.07.20 08:00 Bars_Trader GBPUSD,M1: close #7 sell 0.01 GBPUSD at 2.04810 tp: 2.04720 at price 2.04900
16:01:36 2007.07.25 00:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.25 00:00 Bars_Trader GBPUSD,M1: start= 1
16:01:36 2007.07.25 00:00 Bars_Trader GBPUSD,M1: open #8 sell 0.01 GBPUSD at 2.06160 tp: 2.06070 ok
16:01:36 2007.07.25 02:12 Tester: take profit #8 at 2.06070 (2.06040 / 2.06070)
16:01:36 2007.07.26 08:00 Bars_Trader GBPUSD,M1: start= 0
16:01:36 2007.07.26 08:00 Bars_Trader GBPUSD,M1: start= 0

Show the code more fully. For example right now you can't see where this variable is declared.

 
ilunga:

show the code more fully. For example, right now you can't see where this variable is declared.


extern int TF;
extern int TP;
extern int BARS;
extern int BarrierMinute;
extern int Step=0;
//--------
extern double ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ;
extern double Decrease=2;
extern inttern Wait=2;
extern inttern Repeat;
extern int int MA_Sell;
extern int int Applied_Price_Sell;
//extern int MAPeriod_1;
//extern int Calc=8;
extern double Lots=5;
//----
static int PrevTime=0;
double lots;
int wait,start,step,repeat;
datetime openTime=0;
double lot=0.1;
 
sergovan 26.01.2012 07:27 | banned | delete

Hi, can you tell me how to change orders OP_ BUYSTOP and OP_SELLSTOP in my EA for OP_SELLLIMIT and OP_BUYLIMIT? I tried it and my BUYLIMIT orders are placed, but SELLLIMIT ones don't even think so, maybe I'm doing something wrong?


Attached files:
Expertd10.mq4 (5.82 KB) delete
 

Hello friends, can you please help me with this problem?

I'm writing an Expert Advisor with software stoploss, the basic scheme of algorithm is as follows:


int start()
{double x, PreProfit, TekProfit;
for (x=0; x<1; x++) //The For loop operator (in theory) should be executed 1 time
{PreviousProfit=(-20);}// Assign 1 time value (in theory)!

TextProfit=OrderProfit();//find the profit of the selected order
if (PredPreviousProfit<TekProfit)//if the current profit is higher than the previous one, then...
{WeakProfit=TekProfit;}// Assign the PredCompetitive variable a new value!
//then the PredCompanyProfit variable should hold the highest profit value of all time!
}


The catch is that the value of the variable "x" is reset to zero with a new tick and the value (-20) is assigned to the "PredPreCompetition" variable with every new tick! Thus, the entire sense of the algorithm is lost! The "PrevPreprofit" variable has been designed to constantly keep the maximal value of the order profit until it is forced to "dump" this value when the order is closed.

What is the mistake? Maybe there are other solutions for this problem? I am very grateful in advance!

 
bis:

The catch is that the value of the variable "x" with a new tick is reset to zero and assignment of the value (-20) to the variable "PredPreprofit" is performed every new tick! Thus, the entire sense of the algorithm is lost! The "PrevProfit" variable has been designed to keep the maximal profit value of the order permanently until the forced "reset" of this value when the order is closed.

What is the mistake? Maybe there are other solutions for this problem? Thanks in advance!

See https://docs.mql4.com/ru/basis/variables/static
 
FAQ:
sergovan 26.01.2012 07:27 | banned | delete

Hi, can you tell me how to change orders OP_ BUYSTOP and OP_SELLSTOP in my EA for OP_SELLLIMIT and OP_BUYLIMIT? I tried to change orders BUYLIMIT but SELLLIMIT does not even think so, maybe I am doing something wrong?


Expertd10.mq4 (5.82 KB) Delete


Didn't you forget about Bid and Ask when you changed it?
 

Who knows how to make a standard indicator visible in the strategy tester?

Reason: