[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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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
The reason they didn't reply is probably because writing such an indicator is simple and most likely unnecessary.
Folks, help! I can't calculate the maximum volume of a trade to be opened
Max_lots is always zero!
And the second question, how is the LEVEL calculated?
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?
in simple terms, the volume can be calculated as follows
and level = AccountEquity() / AccountFreeMargin() * 100;
and level = AccountEquity() / AccountFreeMargin() * 100;
NOT correct. This formula does not work out the level
Yes, wrong, level = AccountEquity() / AccountMargin() * 100;
Yes, wrong, level = AccountEquity() / AccountMargin() * 100;
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.