Help for my little knowledge of programming

 

Hi all ... fellow-sufferers ... first apologize for any errors you have to express myself in English because I'm not good ... I'm learning ... like asking someone to help you master the programming because I'm new and while I'm learning a lot, I'm white ... I robots are performed through a website called "Expert Advisor Builder for MetaTrader 4" and then make changes to the result ... one is a patch that gets used in each batch operation necessary for the stop loss if you miss a certain percentage of my capital ... it works well .. but now I'm trying another patch that automatically stop me put it a multiplier StdDev ... this is what you get ... but it does not work ... could someone tell me what is wrong ...

double Limite;
Limite = iStdDev(NULL, 0, 2, 0, MODE_EMA, PRICE_WEIGHTED, 0);
string aux1;
StopLoss = (Limite*2);
aux1 = DoubleToStr(StopLoss,0);
Lots = StrToDouble(aux1);

 

Not sure what you are trying to do . . you need to explain more/better . . .

This isn't needed . . .

StopLoss = (Limite*2); 
aux1 = DoubleToStr(StopLoss,0);
Lots = StrToDouble(aux1);

do this instead

Lots = NormalizeDouble(Limite*2,0); 
 

Sorry about how bad I mean ... see ... I have a patch placed after the initial Star which is what you get now ...

double capital;
capital = AccountFreeMargin();
string aux;
Lots = (((capital/WindowsTotal()) * Perdida) / StopLoss)/MarketInfo(Symbol(), MODE_TICKVALUE);
aux = DoubleToStr(Lots,1);
Lots = StrToDouble(aux);

With this patch we accomplish is that when you open an operation (in forex) use batches if necessary to stop jumping on my lost either the percentage so I say ... this works well ...
What I want now is that I calculate it automatically stop ... and as a percentage of the standart deviation and that is what I put this one ...

double Limite;
Limite = iStdDev(NULL, 0, 2, 0, MODE_EMA, PRICE_WEIGHTED, 0);
string aux1;
StopLoss = (Limite*2);
aux1 = DoubleToStr(StopLoss,0);
StopLoss = StrToDouble(aux1);

The two are related by the lots of places as the stop

 

  1. Lots = (((capital/WindowsTotal()) * Perdida) / StopLoss)/MarketInfo(Symbol(), MODE_TICKVALUE);
    aux = DoubleToStr(Lots,1);
    Lots = StrToDouble(aux);
    The second and third lines round lots to the nearest 0.1. And
    Lots = NormalizeDouble(Limite*2,0); 
    rounds to the nearest int. These assumes that the broker's lotstep is one of 1.0, 0.1, 0.01, etc. A lotstep of 0.05 can not be done that way. Don't hard code numbers:
        double  lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP),   //IBFX= 0.01
                minLot          = MarketInfo(Symbol(), MODE_MINLOT );   //IBFX= 0.10
        Lots=MathCeil(Lots/lotStep)*lotStep; // Round to a multiple of lotStep
        if (Lots < minLot) ...

  2. StopLoss = (Limite*2);
    aux1 = DoubleToStr(StopLoss,0);
    StopLoss = StrToDouble(aux1);
    There's no need for the bottom two lines, at all.
 

Sorry, I do not understand what I put ... you mean with that code ... I get the stop is ... twice the Standard Deviation?? ... because that is what I need but ... StdDev not put anything in the ...

Reason: