int x=0;
int scale_mas[13]={0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096};//объявление массива
for(int i=0;i < ArraySize(scale_mas);i++){
if(x == scale_mas[0])x = scale_mas[1]; //если х=индекс0, то х=индекс1
if(x >= ArraySize(scale_mas))x = scale_mas[11]; //если х>= размер массива, то х=индекс11
i=x;
if(ObjectGetInteger(0, "Button+", OBJPROP_STATE) == false){ //если кнопка "+" нажата
i=i+1; //увеличиваем индекс на 1
ObjectSetInteger(0, "Button+", OBJPROP_STATE,true);}
x=i; //присваиваем х значение последнего индекса
if(ObjectGetInteger(0, "Button-", OBJPROP_STATE) == false){ //если кнопка "-" нажата
i=i-1; //уменьшаем индекс на 1
ObjectSetInteger(0, "Button-", OBJPROP_STATE,true);}
x=i; //присваиваем х значение последнего индекса
ObjectSetString(0,"=TrendLine",OBJPROP_TEXT,scale_mas[x]);}} //выводим результат scale_mas[x]
Yesterday I wrote the code, it seems to work as it should, but only when I get to the top value of the array with the plus button, it resets to the beginning of the array and moves up the array again. What can I add or fix in the code, so that when it reaches the top value of array, further clicks on the plus button will stop at the top index and it will not reset to the bottom of the array? Or can the code be simplified in some other way to implement this button-clicking idea?
Ivan Revedzhuk: Yesterday I wrote the code, it seems to work as it should, but only when I get to the top value of the array with the plus button, it resets to the beginning of the array and moves up the array again. What can I add or fix in the code, so that when it reaches the top value of array, further clicks on the plus button will stop at the top index and it will not reset to the bottom of the array? Or can the code be simplified in some other way to implement this button-clicking idea?
if(x >= ArraySize(scale_mas))
ArraySize(scale_mas)-1; //если х>= размер массива, то ....
Is there any way to do it without it? I just don't know what's best and do what I think is logical.
Well, the logic must be different. Pressing the button + increases the index of the array. Reached the maximum, it does not increase, but stays at the maximum. Pressed the button - the index decreased. Reached zero, does not react to pressing, stays on index 0.
Or was there some other idea?
PS; And who posted the example of working with flags, in response to this question and deleted it? Why did you delete it? After all, it's a really good solution to the man. Why would he need a limited array???
Well, the logic must be different. Pressing the button + increases the array index. Reached the maximum, it does not increase, but stays at the maximum. Pressed the button - the index decreased. Reached zero, does not respond, stays at index 0.
Or was there some other idea?
PS; And who posted the example of working with flags, in response to this question and deleted it? Why did you delete it? After all, it's a really good solution to the man. Why would he need a limited array???
No, that was exactly the idea. I don't really know how to do it properly, so I did it the way I got it. But I've noticed that when the loop is running in the program, as long as I don't click the buttons on the chart, everything else doesn't work. It's like everything is paused. I don't understand why this happens, if there are any variants to implement the idea in any other way, I'd be grateful...
That's it. The problem is solved) without arrays and other stuff. It turned out to be much simpler))))
The second question came up. How can I set Alert triggering level in the code with setting arrow that appears when Alert is set via contextual menu with mouse?
Please help, plz, is it possible to add a function to this EA, so that the EA set in the window EURUSD will open a deal with the same parameters, at the same time, but for GBPUSD, and EURUSD will not open.
Help, plz, is it possible to add a function to this EA, so that the EA installed in the EURUSD window would open a trade with the same opening parameters, at the same time, but on GBPUSD, and not open on EURUSD.
I'm sorry, is your head OK? Not only have you inserted the code in one place, but you've also left a huge amount of empty lines.
Don't you think you should have some respect for who you're asking for help?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Yesterday I wrote the code, it seems to work as it should, but only when I get to the top value of the array with the plus button, it resets to the beginning of the array and moves up the array again. What can I add or fix in the code, so that when it reaches the top value of array, further clicks on the plus button will stop at the top index and it will not reset to the bottom of the array? Or can the code be simplified in some other way to implement this button-clicking idea?
Probably so.
I guess so.
Tried that too, works the same way
Tried that too, works the same way
I didn't notice right away, what's the cycle for?
I didn't notice right away, but what's the loop for?
Is there any way to do it without it? I just don't know what's best and I'm just doing what I think is logical.
Is there any way to do it without it? I just don't know what's best and do what I think is logical.
Well, the logic must be different. Pressing the button + increases the index of the array. Reached the maximum, it does not increase, but stays at the maximum. Pressed the button - the index decreased. Reached zero, does not react to pressing, stays on index 0.
Or was there some other idea?
PS; And who posted the example of working with flags, in response to this question and deleted it? Why did you delete it? After all, it's a really good solution to the man. Why would he need a limited array???Well, the logic must be different. Pressing the button + increases the array index. Reached the maximum, it does not increase, but stays at the maximum. Pressed the button - the index decreased. Reached zero, does not respond, stays at index 0.
Or was there some other idea?
PS; And who posted the example of working with flags, in response to this question and deleted it? Why did you delete it? After all, it's a really good solution to the man. Why would he need a limited array???No, that was exactly the idea. I don't really know how to do it properly, so I did it the way I got it. But I've noticed that when the loop is running in the program, as long as I don't click the buttons on the chart, everything else doesn't work. It's like everything is paused. I don't understand why this happens, if there are any variants to implement the idea in any other way, I'd be grateful...
That's it. The problem is solved) without arrays and other stuff. It turned out to be much simpler))))
The second question came up. How can I set Alert triggering level in the code with setting arrow that appears when Alert is set via contextual menu with mouse?
Please help, plz, is it possible to add a function to this EA, so that the EA set in the window EURUSD will open a deal with the same parameters, at the same time, but for GBPUSD, and EURUSD will not open.
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
//| Developer: Minaev Andrey |
//| Expert Advisor: Stochastic.mq4 |
|| Website: safe-forex.|| Website: safe-forex. |
//| Mail:minaev.work@mail.ru |
//| Skype: live:minaev.work |
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
#property copyright "Safe-Forex.ru"
#property link "https://safe-forex.ru"
#property strict
extern bool Use_Symbol1 = true;
extern string Symbol1 = "USDJPY";
input string settings = ""; // Expert Advisor settings
input int magic = 111; // input magic
input double fixVolume = 0.01; // Volume
input int takeProfit = 500; // Profit
input int stopLoss = 500; //Loss
input int buyLevel = 100; // input int buy Level
input int sellLevel = 0; // 75 Sell Level
extern int ADXperiod = 15; //ADX period 15
extern int ADXLevel =1;
extern int MAperiod =360; //MA period 80
extern int MAperiod_2 =360; //MA period 80
input string stochSettings = ""; // Stochastic Oscillator indicator settings
input int stochPeriodK = 5; //period %K
input int stochPeriodD = 3; //period %D
input int stochSlowing = 3; // Slowing down
input ENUM_STO_PRICE stochPrice = STO_LOWHIGH; // Price
input ENUM_MA_METHOD stochMethod = MODE_SMA; // Method
datetime newCandle; // new candle on the current chart
bool allowOpenBuy; // permission to open Buy position
allowOpenSell; // permission to open Sell position
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
int OnInit(void)
{
return INIT_SUCCEED;
}
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
void OnTick(void)
{
if(newCandle!=Time[0]) CheckSignalExist(); newCandle=Time[0];
if(allowOpenBuy) OpenPosition(OP_BUY);
if(allowOpenSell) OpenPosition(OP_SELL);
}
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
//| Function opens position at current price |
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
void OpenPosition(int type)
{
double price=0.0;
if(type==OP_BUY) price=Ask;
if(type==OP_SELL) price=Bid;
int ticket=OrderSend(_Symbol,type,fixVolume,price,0,0,",magic,0);
// int ticket=OrderSend(,type,fixVolume,price,0,0,0,",magic,0);
Sleep(1000);
if(ticket>0)
{
if(type==OP_BUY)
{
Print("Buy position opened, ticket: ",ticket);
allowOpenBuy=false;
// SetStopOrders(ticket);
}
if(type==OP_SELL)
{
Print("Sell position opened, ticket: ",ticket);
allowOpenSell=false;
// SetStopOrders(ticket);
}
}
if(ticket<0)
{
if(type==OP_BUY) Print("Buy position did not open, error: ",GetLastError());
if(type==OP_SELL) Print("Sell position didn't open, error: ",GetLastError());
}
}
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
//| Function sets stop order |
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
//void SetStopOrders(int ticket)
//{
// double stopLevel=MarketInfo(_Symbol,MODE_STOPLEVEL),
// spread =MarketInfo(_Symbol,MODE_SPREAD),
// tp =takeProfit,
// sl =stopLoss;
// stopLevel+=spread;
// if(tp<stopLevel)
// {
// tp=stopLevel;
// Print("Minimum distance for profit set");
// }
// if(sl<stopLevel)
// {
// sl=stopLevel;
// Print("Minimum distance for loss set");
// }
// if(OrderSelect(ticket,SELECT_BY_TICKET))
// {
// int type=OrderType();
// double opp =OrderOpenPrice();
// if(type==OP_BUY) {tp=opp+tp*_Point; sl=opp-sl*_Point;}
// if(type==OP_SELL) {tp=topp-tp*_Point; sl=opp+sl*_Point;}
// if(OrderModify(ticket,opp,sl,tp,0))
// {
// if(type==OP_BUY) Print("P&L levels set for Buy position, ticket: ",ticket);
// if(type==OP_SELL) Print("P&L levels for the Sell position have been set, ticket: ",ticket);
// }
// else {
// if(type==OP_BUY) Print("P&L levels for the Buy position have not been set, ticket: ",ticket," error: ",GetLastError());
// if(type==OP_SELL) Print("P&L levels for the Sell position have not been set; ticket: ",ticket," error: ",GetLastError();
// }
// }
//}
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
//| Function checks for presence of signal |
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
void CheckSignalExist(void)
{
double ADX1=iADX(Symbol(),Period(),ADXperiod,0,MODE_MAIN,1); ////////////////////////////
double ADX2=iADX(Symbol(),Period(),ADXperiod,0,MODE_MAIN,2);
double DPLUS=iADX(Symbol(),Period(),ADXperiod,0,MODE_PLUSDI,1);
double DMINUS=iADX(Symbol(),Period(),ADXperiod,0,MODE_MINUSDI,1);
double MA=iMA(Symbol(),Period(),MAperiod,0,MODE_SMA,0,1);
double MA_2=iMA(Symbol(),Period(),MAperiod_2,0,MODE_SMA,0,1);
//PERIOD_H1
double mainLine1=iStochastic(_Symbol,PERIOD_CURRENT,stochPeriodK,stochPeriodD,stochSlowing,stochMethod,stochPrice,MODE_MAIN,1),
mainLine2=iStochastic(_Symbol,PERIOD_CURRENT,stochPeriodK,stochPeriodD,stochSlowing,stochMethod,stochPrice,MODE_MAIN,2),
signLine1=iStochastic(_Symbol,PERIOD_CURRENT,stochPeriodK,stochPeriodD,stochSlowing,stochMethod,stochPrice,MODE_SIGNAL,1),
signLine2=iStochastic(_Symbol,PERIOD_CURRENT,stochPeriodK,stochPeriodD,stochSlowing,stochMethod,stochPrice,MODE_SIGNAL,2);
Comment(" ", (Ask-Bid)/1.5," ",Bid-Close[1]," ", Ask-Close[1]);
// if(mainLine1>signLine1 && mainLine2<signLine2 && mainLine1<buyLevel && ADX1>ADXLevel && mainLine2<buyLevel
//& iClose(Symbol(),Period(),1)>MA& iClose(Symbol(),Period(),1)>MA_2 && signLine1<buyLevel && signLine2<buyLevel
if(mainLine1>signLine1 && mainLine2<signLine2 && mainLine1<buyLevel && ADX1>ADXLevel && mainLine2<buyLevel
//&Close[2]<MA& Close[2]<MA_2 && signLine1<buyLevel && signLine2<buyLevel
&&Close[10] > Close[1]-(Close[1]-Close[20])
&& Close[10]>Bid )
{
Print("A signal to open a Buy position has appeared");
if(GetPositionsNumber()==0)
{
// allowOpenSell=true;
{ allowOpenBuy=true;
Sleep(1000);
Print("Allowed to open Buy position");
}
}
// if(mainLine1<signLine1 && mainLine2>signLine2 && mainLine1>sellLevel && ADX1>ADXLevel&& mainLine2>sellLevel
//& iClose(Symbol(),Period(),1)<MA& iClose(Symbol(),Period(),1)<MA_2 && signLine1>sellLevel && signLine2>sellLevel
if(mainLine1>signLine1 && mainLine2<signLine2 && mainLine1<buyLevel && ADX1>ADXLevel && mainLine2<buyLevel
//&Close[2]>MA& Close[2]>MA_2 && signLine1<buyLevel && signLine2<buyLevel
&&Close[10] < Close[1]+(Close[20]-Close[1])
&& Close[10]<Ask )
{
Print("A signal to open a Sell position has appeared");
if(GetPositionsNumber()==0)
{
// allowOpenBuy=true;
allowOpenSell=true;
Sleep(1000);
Print("Allowed to open Sell position");
}
}
}
/////////////////////////////////////////
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
//| The function returns the number of open positions |
//+-------------------------------------------------------------------------------------------------------------------------------------------------+
int GetPositionsNumber(void)
{
int number=0;
for(int i=0; i<OrdersTotal(); i++)
if(OrderSelect(i,SELECT_BY_POS))
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic)
number++;
return number;
}
//+---------------------------------------------------------------------------------------------------------------------------------
Help, plz, is it possible to add a function to this EA, so that the EA installed in the EURUSD window would open a trade with the same opening parameters, at the same time, but on GBPUSD, and not open on EURUSD.
I'm sorry, is your head OK? Not only have you inserted the code in one place, but you've also left a huge amount of empty lines.
Don't you think you should have some respect for who you're asking for help?