Opinión MA Price intersection sample

 

Publi

MA Price intersection sample

 

Publi

Resultados 1 al 2 de 2


  1. #1




    Reputación:
    Poder de reputación: 7

    Espana
    Mensajes: 2
    Créditos: 80

    MA Price intersection sample


    Publi
    Hola, buenas noches a todos los que me estáis leyendo y un saludo a todo el foro en general.

    Les comento un poco mi caso, estoy trabajando en robots de mecánica muy sencilla para introducir mejoras que hagan de ellos una máquina que bajo control reporten beneficios consistentes. En fin, hay todo un mundo ahí fuera.

    El caso es que recientemente he tenido que formatear el ordenador y he perdido algunos de los ejemplos que tenía trabajados y que ahora estoy intentando reconstruir. Ahí les dejo este ejemplo, por si alguien puede echarlo un vistazo rápido y encontrar el error:

    /+------------------------------------------------------------------+
    //| Price intersection sample.mq4 |
    //| Copyright 2017, David J. Díez Munilla |
    //| https://www.mql5.com/users/ECway |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2017, David J. Díez Munilla"
    #property link "https://www.mql5.com/users/ECway"
    #property description "Simple price intersection expert advisor"
    #property description "Clean version with Slow MA trend filter."
    #property version "1.00"
    #property strict
    #define BOTNAME "Price intersection sample"
    #define MAGICNUM 12358
    //---------------------------------------------- Input parameters ---!
    input double StartLotSize = 0.05;
    input int FastMAPeriod = 50;
    input int SlowMAPeriod = 100;
    input int TakeProfit = 100;
    input int TrailingStop = 50;
    input int BreakPoint = 25;
    input int StopLoss = 0;
    //---------------------------------------------- Money management ---!
    double LotsOptimized(){
    double lot=(((AccountFreeMargin()*(3/100))*AccountLeverage())/100000);
    return(lot);
    if(lot<StartLotSize){
    return(StartLotSize);
    }
    }
    //+------------------------------------------------------------------+
    //| Expert initialization function |
    //+------------------------------------------------------------------+
    int OnInit(){return(INIT_SUCCEEDED);}
    //+------------------------------------------------------------------+
    //| Expert deinitialization function |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason){}
    //+------------------------------------------------------------------+
    //| Expert tick function |
    //+------------------------------------------------------------------+
    void OnTick(){
    //----------------------------------------- Internal variables ---!
    double FastMA=iMA(NULL,0,FastMAPeriod,6,MODE_EMA,PRICE_CL OSE,0);
    double SlowMA=iMA(NULL,0,SlowMAPeriod,6,MODE_SMMA,PRICE_C LOSE,0);
    double UpTREND=FastMA>SlowMA;
    double DownTREND=FastMA<SlowMA;
    int BUYsignal=UpTREND&&Open[1]<FastMA&&FastMA<Close[1];
    int SELLsignal=DownTREND&&Open[1]>FastMA&&FastMA>Close[1];
    int cnt, ticket;
    //------------------------------------------------------ Start ---!
    // Check for LONG
    if(BUYsignal){
    ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),A sk,3,0,0,BOTNAME,MAGICNUM,0,Blue);
    }
    // Check for SHORT
    if(SELLsignal){
    ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized(), Bid,3,0,0,BOTNAME,MAGICNUM,0,Red);
    }
    for(cnt=0;cnt<OrdersTotal();cnt++){
    if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)&&Or derSymbol()==Symbol()){
    // Exit LONG
    if(OrderType()==OP_BUY){
    //--- Close by TAKE PROFIT
    if(TakeProfit>0&&Bid>=OrderOpenPrice()+TakeProfit* Point){
    OrderClose(OrderTicket(),OrderLots(),3,Green);
    return;
    }
    //--- Check for TRAILING STOP
    if(TrailingStop>0){
    if(Bid-OrderOpenPrice()>Point*TrailingStop){
    if(OrderStopLoss()<Bid-Point*TrailingStop){
    //--- modify order and exit
    if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,MediumPurpl e)){
    Print("OrderModify error ",GetLastError());
    }
    return;
    }
    }
    }
    //--- Check for REVERSAL
    if(BreakPoint>0&&SELLsignal&&Bid>=OrderOpenPrice()-BreakPoint*Point){
    OrderClose(OrderTicket(),OrderLots(),3,SlateGray);
    ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),A sk,3,0,0,BOTNAME,MAGICNUM,0,Blue);
    }
    //--- Exit by STOP LOSS
    if(StopLoss>0&&Bid<=OrderOpenPrice()-StopLoss*Point){
    OrderClose(OrderTicket(),OrderLots(),3,Black);
    return;
    }
    }
    // Exit SHORT
    else if(OrderType()==OP_SELL){
    //--- Close by TAKE PROFIT
    if(TakeProfit>0&&Ask>=OrderOpenPrice()-TakeProfit*Point){
    OrderClose(OrderTicket(),OrderLots(),3,Green);
    return;
    }
    //--- Check for TRAILING STOP
    if(TrailingStop>0){
    if(Ask-OrderOpenPrice()>Point*TrailingStop){
    if(OrderStopLoss()<Ask-Point*TrailingStop){
    //--- modify order and exit
    if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*TrailingStop,OrderTakeProfit(),0,MediumPurpl e)){
    Print("OrderModify error ",GetLastError());
    }
    return;
    }
    }
    }
    //--- Check for REVERSAL
    if(BreakPoint>0&&BUYsignal&&Ask<=OrderOpenPrice()+ BreakPoint*Point){
    OrderClose(OrderTicket(),OrderLots(),3,SlateGray);
    ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),B id,3,0,0,BOTNAME,MAGICNUM,0,Blue);
    }
    //--- Exit by STOP LOSS
    if(StopLoss>0&&Ask<=OrderOpenPrice()+StopLoss*Poin t){
    OrderClose(OrderTicket(),OrderLots(),3,Black);
    return;
    }
    }
    }
    }
    //---
    }
    //+------------------------------------------------------------------+

    Lo que hace básicamente es utilizar una media lente como filtro de tendencia para entrar cuando el precio cruce la media rápida al alza o a la baja según se dén las circunstancias. Además incluye un módulo de Money management y el límite de pérdidas en señal opuesta (es muy bajo) y tras lo cuál intento abrir una nueva posición en contrario. Ahora mismo no me da ningún resultado en el backtest.Price intersection.mq4
    Foro de Forex Trading United

  2. Publi
    Publi


  3. #2




    Reputación:
    Poder de reputación: 10

    Espana
    Mensajes: 35
    Créditos: 1.074

    Re: MA Price intersection sample


    Publi
    Hola, en el calculo del lotaje, segun que broker necesitas un minimo de lote para una transacion, o redondear para que no salgan decimales en el lote
    Foro de Forex Trading United

This website uses cookies
Utilizamos cookies propias y de terceros para elaborar información estadística y mostrarle publicidad personalizada a través del análisis de su navegación. Si continúa navegando acepta su uso. Más información y política de cookies.
     

 

Publi


Aviso Legal
Ley Orgánica 15/1999, de 13 de diciembre, de Protección de Datos de Carácter Personal