[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 594

 

I took probability theory and statistically if order opening will be within 50 pips from the price, then at opening order with 10 pips profit is easier to reach - if there will also be 10 pips stop loss (even spread is not a problem) the movement of trend is a great thing ...

Add a stop loss, regardless of StepStop

//+------------------------------------------------------------------+
//| Volfram.mq4 |
//| Vova-x@list.ru |
//| |
//+------------------------------------------------------------------+
#property copyright "Vova-x@list.ru"
#property link ""
//-----------------------------------------
extern TakeProfit=10;
extern int StepStop=45;
extern double Lots=0.01;
extern bool MoneyManagement=true;
extern inttern MarginPercent=10;
//-------------------------------------------
int level_sell_stop;
int level_buy_stop;

//----------------------------------------------------------
void init()
{
// int minstop=MarketInfo(Symbol(),MODE_STOPLEVEL);
//Print("levelbuy_stop: "+minstop;)
}
//-----------------------------------------------------------
void start()
{
if (!IsTradeAllowed()) return;
level_buy_stop=0;
level_sell_stop=0;
StepingStop();
StepingPendings();
if (TotalBuy ()==0 && TotalBuyStop ()==0) SetBuyStop ();
if (TotalSell()==0 && TotalSellStop()==0) SetSellStop();
Comment("Level Buy Stop=",level_buy_stop*Point,
"\n", "Level Sell Stop=",level_sell_stop*Point);
}
//---------------------------------------------------------------------------------------------
void StepingStop()
{
if (StepStop<1) return;
int ask, bid, open, stop, x;
double loss;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol())
if (OrderType()==OP_BUY)
{
bid=MathRound(Bid/Point);
open=MathRound(OrderOpenPrice()/Point);
stop=MathRound(OrderStopLoss()/Point);
x=(bid-open)/StepStop; x--; x*=StepStop;
level_sell_stop=open+x;
if (stop>=open+x)
loss=(open+x)*Point;
OrderModify(OrderTicket(),OrderOpenPrice(),loss,OrderTakeProfit(),0,CLR_NONE);
}
if (OrderType()==OP_SELL)
{
ask=MathRound(Ask/Point);
open=MathRound(OrderOpenPrice()/Point);
stop=MathRound(OrderStopLoss()/Point);
x=(open-ask)/StepStop; x--; x*=StepStop;
level_buy_stop=open-x;
if (stop>0 && stop<=open-x)
loss=(open-x)*Point;
OrderModify(OrderTicket(),OrderOpenPrice(),loss,OrderTakeProfit(),0,CLR_NONE);
}
}
}
//----------------------------------------------------------------------------
void StepingPendings()
{
int ask, bid, open;
double price, loss, profit;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol())
if (OrderType()==OP_BUYSTOP)
{
if (level_buy_stop==0)
open=MathRound(OrderOpenPrice()/Point);
if (open<=level_buy_stop)
price=level_buy_stop*Point;
loss=price-StepStop*Point;
profit=0; if (TakeProfit>0) profit=price+TakeProfit*Point;
OrderModify(OrderTicket(),price,loss,profit,0,CLR_NONE);
}
if (OrderType()==OP_SELLSTOP)
{
if (level_sell_stop==0)
open=MathRound(OrderOpenPrice()/Point);
if (open>=level_sell_stop)
price=level_sell_stop*Point;
loss=price+StepStop*Point;
profit=0; if (TakeProfit>0) profit=price-TakeProfit*Point;
OrderModify(OrderTicket(),price,loss,profit,0,CLR_NONE);
}
}
}
//-------------------------------------------------------------------
void SetBuyStop()
{
double lots=LotsCounting();
double price=Bid+StepStop*Point;
double loss=price-StepStop*Point;
double profit=0; if (TakeProfit>0) profit=price+TakeProfit*Point;
int ticket=OrderSend(Symbol(),OP_BUYSTOP,lots,price,0,loss,profit,"",0,0,CLR_NONE);
if (ticket<1) Print("Set a pending order failed with error #",GetLastError()," ",(GetLastError());
}

void SetSellStop()
{
double lots=LotsCounting();
double price=Ask-StepStop*Point;
double loss=price+StepStop*Point;
double profit=0; if (TakeProfit>0) profit=price-TakeProfit*Point;
int ticket=OrderSend(Symbol(),OP_SELLSTOP,lots,price,0,loss,profit,"",0,0,CLR_NONE);
if (ticket<1) Print("Set a pending order failed with error #",GetLastError()," ",(GetLastError());
}


int TotalBuy()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_BUY) count++;
}
return (count);
}

int TotalBuyStop()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_BUYSTOP) count++;
}
return (count);
}

int TotalSell()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_SELL) count++;
}
return (count);
}

int TotalSellStop()
{
int count=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()==OP_SELLSTOP) count++;
}
return (count);
}

double LotsCounting()
{
double lots=Lots;
if (MoneyManagement)
{
double lotsize=MarketInfo(Symbol(),MODE_LOTSIZE);
double freemargin=AccountFreeMargin();
lots=0; if (lotsize>0) lots=NormalizeDouble((MarginPercent*freemargin/lotsize),1);
}
if (lots>10) lots=NormalizeDouble(lots,0);
if (lots<0.01) lots=0.01;
return (lots);
}


// End

 
drknn:

The reason they didn't reply is probably because writing such an indicator is simple and most likely unnecessary.
Thanks, but what about it? Or tell me, maybe in the terminal settings, there is a possibility to show hour marks more clearly along the entire length of the time scale?
 

Folks, help! I can't calculate the maximum volume of a trade to be opened

// Расчет максимального объема
   for (double m = 0.1; AccountFreeMarginCheck(Symbol(),OP_SELL,m)>30; m = m + 0.1)
      {
       Max_lots   = m;
       double Ost = AccountFreeMarginCheck(Symbol(),OP_SELL,m);
      }

Max_lots is always zero!


And the second question, how is the LEVEL calculated?


 
root:
Thanks, but still? Or tell me, maybe in the terminal settings, there is an option to show the hour markers more clearly along the entire length of the time scale?
I get it, the lack of this indicator is the last thing stopping you from making money in forex. Definitely no such thing, but Urain has a similar one for 8 lines. If you can't, ask the author, he's on the forum.
Files:
time_line.mq4  2 kb
 

in simple terms, the volume can be calculated as follows

/* вычитаем средства обозначенные на стопаут c учетом процента риска */
   curBalance = AccountFreeMargin() * (1 - AccountStopoutLevel() / 100.) * percent; // percent - от 0 до 100
/* множитель (1 или 10) зависит от четырех-пятизначности  */
   koeff = iif(DIGITS == 3 || DIGITS == 5, 10, 1);
/* расчет рабочего лота, нормализация */
   lot = NL(curBalance / (koeff * lossPoint * TICKVALUE + MARGINREQUIRED)); //lossPoint - количество пунктов потерь
   if (lot < MINLOT)    lot = 0;
   if (lot > MAXLOT)    lot = MAXLOT;

/* DIGITS,MINLOT,MAXLOT,TICKVALUE,MARGINREQUIRED получаем из Marketinfo() */


and level = AccountEquity() / AccountFreeMargin() * 100;

 
keekkenen:



and level = AccountEquity() / AccountFreeMargin() * 100;

is NOT correct. This formula does not work out Level
 
Noterday:
NOT correct. This formula does not work out the level

Yes, wrong, level = AccountEquity() / AccountMargin() * 100;

 
keekkenen:

Yes, wrong, level = AccountEquity() / AccountMargin() * 100;

Thanks :)
 
Hello. Guys, please help me with one thing. I haven't even heard of it - but what if someone has it? The idea is to transfer all the selected objects from one chart to another. I.e., suppose I need to transfer the wave markup of all times of one symbol into one window. It is difficult to repeat the mark-up switching timeframes, because of the heaviness of the calculation (calculation of 30-50 trends on M1 makes the terminal stand out - and it is only about 16 - 24 hours of a chart). Maybe there is a script that copies the objects on the chart (in this case - trendlines) with the subsequent transfer of the entire array of trendlines into another window? Or maybe there is a possibility to combine several templates in one window?
 

Sorry for the flub, but today's the day.

=====

And swing to a meaningless height...

A couple of phrases that flew in from here...

===========

Andrei Voznesensky.

Reason: