
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
Hi
Please tell me how to post code - so that it goes into a box that others can easily copy.
ThanksYou may post the code as simple text.
But better is to post it betweet this sign # like this:
testing
hi
some code:
{
int i,hstTotal=HistoryTotal();
int losses;
static double val1;
for(i=hstTotal-1;i>=0;i--)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==fals e)
{
Print("Access to history failed with error (",GetLastError(),")");
break;
}
if(OrderProfit()>0){
val1 = 0;
break;
}
if(OrderProfit()<0) {
losses++;
val1 = val1 + orderProfit();
}
if(losses==2) {
lotMM = MathCeil(AccountFreeMargin() * 50 / 10000) / 10; // 50 risk
if (lotMM < 0.1) lotMM = Lots;
if (lotMM > 1.0) lotMM = MathCeil(lotMM);
if (lotMM > 100) lotMM = 100;
}
}Got it - thanks - were would one find the different html tags one can use on this forum?
vB code
were would one find the different html tags one can use on this forum?
Follow this link vB code
Thanks
Thanks codesguru
Zero Loss Code?
Hi,
Please help a newbie here!
Can anyone write the code (MQL4) to modify the StopLoss of an Order after the profit has reached X pips? I want to include this code into an EA. I would like to raise the StopLoss to the level of 0 profit in order to not lose anything if the market goes against my position. This way the position will close at 0 P/L. This is very useful when your position is making only few pips (not enough to trigger the trailing stop) and after that, the prices go to the oposite direction, making you lose.
Thank you.
Hello,
I am not sure if this could be integrated into your EA, but I put a separate fonction that you can put at the end of the code and call during the main loop.
Make sure you have a global variable "Magic" that you are using when placing order:
----
int Magic;
-----
Also you need to set the number of pips in profit "ProfitModifySL" before you would like to set your stopLoss to the actual opening price:
----
extern double ProfitModifySL=15; // After being in 15 pips Profit Stoploss is adjusted to the opening price of the order
-----
//+------------------------------------------------------------------+
//| Scan through Order and if in profit by PrmSL Modify SL |
//+------------------------------------------------------------------+
void fModifySLWhenInProfit()
{
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if (OrderType()==OP_BUY && Bid-OrderOpenPrice()>=ProfitModifySL*Point)
fModifyStopLoss(OrderOpenPrice());
if (OrderType()==OP_SELL && OrderOpenPrice()-Ask>=ProfitModifySL*Point)
fModifyStopLoss(OrderOpenPrice());
}
}
}
}
//+------------------------------------------------------------------+
//| Modify Stop Loss |
//+------------------------------------------------------------------+
void fModifyStopLoss(double tStopLoss)
{
bool result = OrderModify(OrderTicket(),OrderOpenPrice(),tStopLoss,OrderTakeProfit(),0,NULL);
}
Otherwise I attached to the post a simple EA that does it.
Hope this help
Cheers
Thank You sunwest!
You are welcome, also to avoid to modify your orders all the time and do it once you could change:
if (OrderType()==OP_BUY && Bid-OrderOpenPrice()>=ProfitModifySL*Point)
fModifyStopLoss(OrderOpenPrice());
if (OrderType()==OP_SELL && OrderOpenPrice()-Ask>=ProfitModifySL*Point)
fModifyStopLoss(OrderOpenPrice());
to
if (OrderType()==OP_BUY && Bid-OrderOpenPrice()>=ProfitModifySL*Point)
if (OrderStopLoss()<OrderOpenPrice()) fModifyStopLoss(OrderOpenPrice());
if (OrderType()==OP_SELL && OrderOpenPrice()-Ask>=ProfitModifySL*Point)
if (OrderStopLoss()>OrderOpenPrice()) fModifyStopLoss(OrderOpenPrice());
S.
Vertical line production in mql code
Hi folks,
I am interested in an mql code set that can produce a vertical line on a chart at a selectable time. Does anything like this exist or can it be coded??
My understanding of mql codes are very minimal and I cannot code anything. The best I can do is change the colour of 'objects' and their density.
My appreciation to any and all who respond and to this wonderful forum...
Good trading to all.......................
similar boat
I'm up against the same thing... but instead of having a line (more clutter) i'd like to ahve a candle colored... again it needs to be user input so we can show the opens of various markets... as an example.
konjn