I write indicators, EAs, not for free anymore :) - page 6

 
KimIV >> :
Incorrect function parameters. Check exactly what you pass to OrderClose() function.

Checked it... Really don't know what's the problem... I've tried so many different things %(

 

Good evening again :)

With a new request. I realized that I won't be able to figure it out on my own anyway.

I am asking to write an EA based on the WATR indicator (EA code below). When the indicator makes a turn, it closes the open order (if it has not been closed by SL or TP) and opens a new order in the direction shown by the indicator. We open only one order exactly at the reversal point. Then we wait until the next reversal of the EA.

Input parameters: lot size, SL, TP, slippage. I think I have not forgotten anything :)

Regards, Svetlana. ICQ 320355718

Code of the indicator:

//+------------------------------------------------------------------+
//| WATR.mq4
//| Written by WizardSerg under article konkop in |
//| "Modern trading" #4/2001 |
//| http://www.wizardserg.inweb.ru |
//| wizardserg@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Written by WizardSerg under article konkop in <Modern trading> #4/2001"
#property link "http://www.wizardserg.inweb.ru"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Coral
#property indicator_color2 DodgerBlue
//---- input parameters
extern inttern WATR_K = 10;
extern double WATR_M = 4.0;
extern inttern ATR = 21;
//---- buffers
double ExtMapBufferUp[];
double ExtMapBufferDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0, ExtMapBufferUp);
ArraySetAsSeries(ExtMapBufferUp, true);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, ExtMapBufferDown);
ArraySetAsSeries(ExtMapBufferDown, true);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
IndicatorShortName("WATR(" + WATR_K + ", " + WATR_M + ")");
SetIndexLabel(0, "WATR_Up");
SetIndexLabel(1, "WATR_Dn");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator function |
//+------------------------------------------------------------------+
bool AntiTrendBar(int i)
{
bool res = (TrendUp(i) && (Close[i] < Open[i]) ||
(!TrendUp(i) && (Close[i] > Open[i]);
return(res);
}
//+------------------------------------------------------------------+
//| Custom indicator function ||
//+------------------------------------------------------------------+
double CalcIndicValue(int i, bool trend)
{
double res = Close[i];
if(trend)
res -= (WATR_K*Point + WATR_M*iATR(NULL, 0, ATR, i))
else
res += (WATR_K*Point + WATR_M*iATR(NULL, 0, ATR, i));
return(res);
}
//+------------------------------------------------------------------+
//| Custom indicator function |
//+------------------------------------------------------------------+
bool TrendUp(int i)
{
return((Close[i+1] > ExtMapBufferUp[i+1]) &&
(ExtMapBufferUp[i+1] != EMPTY_VALUE))
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
//---- the last counted bar will be recalculated
//---- first indicator value == price-1 point,
//that is, it considers the trend to be upward
ExtMapBufferUp[Bars] = Close[Bars] - WATR_K*Point;
// limit = (counted_bars > 0) ? (Bars - counted_bars) : (Bars - 1);
limit = Bars - counted_bars;
//---- main loop
for(int i = limit; i >= 0; i--)
{
if(AntiTrendBar(i))
{
ExtMapBufferUp[i] = ExtMapBufferUp[i+1];
ExtMapBufferDown[i] = ExtMapBufferDown[i+1];
}
else
{
if(TrendUp(i))
{
ExtMapBufferUp[i] = CalcIndicValue(i, true);
if(ExtMapBufferUp[i] < ExtMapBufferUp[i+1])
ExtMapBufferUp[i] = ExtMapBufferUp[i+1];
ExtMapBufferDown[i] = EMPTY_VALUE;
}
else
{
ExtMapBufferDown[i] = CalcIndicValue(i, false);
if(ExtMapBufferDown[i] > ExtMapBufferDown[i+1])
ExtMapBufferDown[i] = ExtMapBufferDown[i+1];
ExtMapBufferUp[i] = EMPTY_VALUE;
}
}
// crossing price
if(TrendUp(i) && (Close[i] < ExtMapBufferUp[i])
{
ExtMapBufferDown[i] = CalcIndicValue(i, false);
ExtMapBufferUp[i] = EMPTY_VALUE;
}
if((!TrendUp(i)) && (Close[i] > ExtMapBufferDown[i])
{
ExtMapBufferUp[i] = CalcIndicValue(i, true);
ExtMapBufferDown[i] = EMPTY_VALUE;
}
}
return(0);
}
//+------------------------------------------------------------------+



 
rusmos писал(а) >>

Excuse me, but could you please write some code for the following problem - the first lot, for example 0.1, and each next lot increases by a certain, given value.

Thank you in advance.

Search this forum, such already asked and written...

In any case there is something similar...

 
StatBars >> :

Search this forum, it's been asked and written about...

Thanks >> I've been poking around the forum for about three hours now, found a lot, but not this.

 
StatBars >> :

Search this forum, it's been asked and written before...

And the code is probably 10 terms at the most.

But I guess they don't go for petty stuff here.

 
rusmos >> :

And the code is probably 10 terms at the most.

But I guess professionals don't go for trifles here.

It would be nice to formalise the task not just approximately, but concretely, so that someone would take it on.

 
rusmos писал(а) >>

And the code is probably 10 terms at the most.

But the pros probably don't go for the small stuff here.

Please formulate your question correctly. The first order, the subsequent ones. The first from what? From the beginning of the Universe, or from the day Christ came, or the creation of the world, or maybe from the moment you had breakfast and went for a walk? What are the questions, what are the answers.

 
rusmos писал(а) >>

And the code is probably 10 terms at the most.

But I guess they don't go for the little things here.

extern double RISK=20;


lotsize=MarketInfo(Symbol(),MODE_LOTSIZE)*0.01;
Balance=AccountBalance()*( RISK/100);
lots=NormalizeDouble( Balance/ lotsize,2); // - это и есть лот для открытия позиции
The code not only increases the lot, but also reduces it, it all depends on the depo, the depo goes up - the lot goes up... I thought you needed this...
 
sol >> :

It would be nice to formalise the task not just approximately, but concretely, so that someone could take it on.

OK. The first lot is Buy with lot 0.1. In response, the SellStop is immediately set at 20 points from the bottom with 0.2 lot (i.e. increase by 0.1)

Further, if the Sell has triggered, in the answer we set the Bystop with 0.3 lot (i.e. increase the LAST lot again by 0.1) and in principle so-and-so.

It is important that the magnitude of the increase in lot should be adjusted at your discretion.

Well, respectively, two interesting options. Addition and multiplication.

>> Ugh, I think that's it.)

 
StatBars >> :
The code not only increases the lot but also decreases it, it all depends on the depo, the depo goes up - the lot goes up... I thought you needed this...

The size of the deposit does not matter.