Heikin Ashi + Renko charts combined

Forums ProRealTime English forum ProBuilder support Heikin Ashi + Renko charts combined

  • This topic has 5 replies, 4 voices, and was last updated 7 years ago by avatar211.
Viewing 6 posts - 1 through 6 (of 6 total)
  • #18930
    211

     

    Hi traders,

    I want to start a topic about Heikin Ashi charts and Renko charts.

    I love Heikin Ashi chart because it gives me clarity. It reduces a lot of noise in the chart and let me see the trend in the market.

    Renko chart are even more clear and simple but are lacking certain information.

    I saw something online that really peeked my interest. A combination between a Heikin Ashi chart and Renko chart.

    Here is an example that I found on youtube.

    Basic Renko + Heikin Ashi Strategy

    https://www.youtube.com/watch?v=8Q6no5s2ULA&t=82s

    I wonder if it is possible to program something like that in PRT 10.3.

    Fabius

    #18943

    Seems interesting indeed, thanks for posting it here.

    Because Renko candles are non time dependent and applying indicators on them on PRT is not possible (unless only some of them), it means that to build this “renko-heikin ashi” candlesticks, the only possibility would be to use the default price chart. So the visual of the candlesticks would not be so ‘smooth’ than the one you show on the picture attached in your post.

    I got some ideas to do it, but I’d like to dig into the code of this indicator that build this kind of renko bricks. Do you have it? If yes, please share the file so I can investigate into it.

    #18952
    211

    Hi Nicolas,

    Thank you for answering my post. I haven’t got any code myself but found this link about Heikin Ashi + Renko: http://www.pimpmyea.com/heiken-ashi-and-renko-perfect-synergy/

    And found some code from I think from the Metatrader platform:

    //+—————————————————————————-+
    //| _Expert Advisor.mq4 | Renko Ashi System
    //| Copyright � 2009-2010, TradingSystemForex.Com |
    //| http://www.tradingsystemforex.com/ |
    //| 01.18.2010 |
    //+—————————————————————————-+

    #property copyright “Copyright � 2009-2010, TradingSystemForex.Com”
    #property link “http://www.tradingsystemforex.com/”

    extern string comment=”EA”; // comment to display in the order
    extern int magic=1234; // magic number required if you use different settings on a same pair, same timeframe

    extern string moneymanagement=”Money Management”;

    extern double lots=0.1; // lots size
    extern bool mm=false; // enable risk management
    extern double risk=1; // risk in percentage of the account
    extern double minlot=0.01; // minimum lots size
    extern double maxlot=50; // maximum lots size
    extern int lotdigits=2;
    //extern bool martingale=false; // enable the martingale
    //extern double multiplier=2.0; // multiplier used for the martingale
    //extern bool basketpercent=false; // enable the basket percent
    //extern double profit=10; // close all orders if a profit of 10 percents has been reached
    //extern double loss=30; // close all orders if a loss of 30 percents has been reached

    extern string ordersmanagement=”Order Management”;

    extern bool ecn=false; // make the expert compatible with ecn brokers
    extern bool oppositeclose=true; // close the orders on an opposite signal
    extern bool reversesignals=false; // reverse the signals, long if short, short if long
    extern int maxtrades=100; // maximum trades allowed by the traders
    extern int tradesperbar=1; // maximum trades per bar allowed by the expert
    extern bool hidesl=false; // hide stop loss
    extern bool hidetp=false; // hide take profit
    extern double stoploss=0; // stop loss
    extern double takeprofit=0; // take profit
    extern double trailingstart=0; // profit in pips required to enable the trailing stop
    extern double trailingstop=0; // trailing stop
    //extern double trailingprofit=0; // trailing profit
    extern double trailingstep=1; // margin allowed to the market to enable the trailing stop
    extern double breakevengain=0; // gain in pips required to enable the break even
    extern double breakeven=0; // break even
    int expiration=0; // expiration in minutes for pending orders
    double slippage=0; // maximum difference in pips between signal and order
    extern double maxspread=100; // maximum spread allowed by the expert

    extern string adordersmanagement=”Advanced Order Management”;

    extern bool autosl=true;
    extern int stoplevel=15;

    extern string entrylogics=”Entry Logics”;

    extern bool changedirection=false;
    extern bool machannelsignal=true;
    extern int maperiod=5;
    extern bool mainappliedpricefilter=true;
    extern int MAPeriod=10;
    extern int MAType=3;
    extern int MAAppliedPrice=6;
    extern bool smc4scalperfilter=true;
    extern bool macdfilter=true;
    extern int FastEMA=5;
    extern int SlowEMA=10;
    extern int SignalSMA=2;
    extern int shift=1; // bar in the past to take in consideration for the signal
    /*
    extern string timeout=”Time Outs and Targets Settings”;

    extern bool usetimeout=true;
    extern int timeout1=30;
    extern int target1=7;
    extern int timeout2=70;
    extern int target2=5;
    extern int timeout3=95;
    extern int target3=4;
    extern int timeout4=120;
    extern int target4=2;
    extern int timeout5=150;
    extern int target5=-5;
    extern int timeout6=180;
    extern int target6=-8;
    extern int timeout7=210;
    extern int target7=-15;
    */

    extern string timefilter=”Time Filter”;

    extern int summergmtshift=2; // gmt offset of the broker
    extern int wintergmtshift=1; // gmt offset of the broker
    extern bool mondayfilter=false; // enable special time filter on friday
    extern int mondayhour=12; // start to trade after this hour
    extern int mondayminute=0; // minutes of the friday hour
    extern bool weekfilter=false; // enable time filter
    extern int starthour=7; // start hour to trade after this hour
    extern int startminute=0; // minutes of the start hour
    extern int endhour=21; // stop to trade after this hour
    extern int endminute=0; // minutes of the start hour
    extern bool tradesunday=true; // trade on sunday
    extern bool fridayfilter=false; // enable special time filter on friday
    extern int fridayhour=12; // stop to trade after this hour
    extern int fridayminute=0; // minutes of the friday hour

    datetime t0,t1,tstart,tend,tfriday,tmonday,lastbuyopentime,lastsellopentime,time;
    int i,bc=-1,cnt,tpb,tps,tries=100,lastorder,buyorderprofit,sellorderprofit,lotsize;
    int nstarthour,nendhour,nfridayhour,nmondayhour,number,ticket,gmtshift,tradetime;
    string istarthour,istartminute,iendhour,iendminute,ifridayhour,ifridayminute,imondayhour,imondayminute;
    double cb,sl,tp,ilots,lastbuylot,lastselllot,lastlot,lastprofit,mlots,win[14],sum[14];
    double lastbuyopenprice,lastsellopenprice,lastbuyprofit,lastsellprofit,tradeprofit;

    bool closebasket=false;

    bool continuebuy=true;
    bool continuesell=true;

    double pt,mt;
    int dg;

    int init(){
    t0=Time[0];
    t1=Time[0];

    sum[2012-1999]=D’2012.03.28 02:00:00′;win[2012-1999]=D’2012.10.31 03:00:00′;
    sum[2011-1999]=D’2011.03.29 02:00:00′;win[2011-1999]=D’2011.10.25 03:00:00′;
    sum[2010-1999]=D’2010.03.30 02:00:00′;win[2010-1999]=D’2010.10.26 03:00:00′;
    sum[2009-1999]=D’2009.03.29 02:00:00′;win[2009-1999]=D’2009.10.25 03:00:00′;
    sum[2008-1999]=D’2008.03.30 02:00:00′;win[2008-1999]=D’2008.10.26 03:00:00′;
    sum[2007-1999]=D’2007.03.25 02:00:00′;win[2007-1999]=D’2007.10.28 03:00:00′;
    sum[2006-1999]=D’2006.03.26 02:00:00′;win[2006-1999]=D’2006.10.29 03:00:00′;
    sum[2005-1999]=D’2005.03.27 02:00:00′;win[2005-1999]=D’2005.10.30 03:00:00′;
    sum[2004-1999]=D’2004.03.28 02:00:00′;win[2004-1999]=D’2004.10.31 03:00:00′;
    sum[2003-1999]=D’2003.03.30 02:00:00′;win[2003-1999]=D’2003.10.26 03:00:00′;
    sum[2002-1999]=D’2002.03.31 02:00:00′;win[2002-1999]=D’2002.10.27 03:00:00′;
    sum[2001-1999]=D’2001.03.25 02:00:00′;win[2001-1999]=D’2001.10.28 03:00:00′;
    sum[2000-1999]=D’2000.03.26 02:00:00′;win[2000-1999]=D’2000.10.29 03:00:00′;
    sum[1999-1999]=D’1999.03.28 02:00:00′;win[1999-1999]=D’1999.10.31 03:00:00′;

    dg=Digits;
    if(dg==3 || dg==5){pt=Point*10;mt=10;}else{pt=Point;mt=1;}
    if(minlot>=1){lotsize=100000;}
    if(minlot<1){lotsize=10000;}
    if(minlot<0.1){lotsize=1000;}
    return(0);
    }

    int start(){
    /*
    GlobalVariableSet(“vGrafBalance”,AccountBalance());
    GlobalVariableSet(“vGrafEquity”,AccountEquity());
    */

    if(breakevengain>0)movebreakeven(breakevengain,breakeven);
    if(trailingstop>0)movetrailingstop(trailingstart,trailingstop);
    //if(trailingprofit>0)movetrailingprofit(trailingstart,trailingprofit);
    /*
    if(basketpercent){
    if(closebasket==false)closebasket=closebasketpercent(profit,loss);
    if(closebasket){closebuy();closesell();delete(OP_BUYSTOP);delete(OP_SELLSTOP);delete(OP_BUYLIMIT);delete(OP_SELLLIMIT);}
    if(closebasket && count(OP_BUY)+count(OP_SELL)+count(OP_BUYLIMIT)+count(OP_SELLLIMIT)+count(OP_BUYSTOP)+count(OP_SELLSTOP)==0)closebasket=false;
    }
    */
    if(OrdersTotal()>0){
    for(i=0;i<=OrdersTotal();i++){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderCloseTime()==0){
    if(OrderType()==OP_BUY){
    lastbuyopentime=OrderOpenTime();
    //lastbuyopenprice=OrderOpenPrice();
    //buyorderprofit=OrderProfit();
    }
    if(OrderType()==OP_SELL){
    lastsellopentime=OrderOpenTime();
    //lastsellopenprice=OrderOpenPrice();
    //sellorderprofit=OrderProfit();
    }
    }
    }
    }
    if(tradesperbar==1){
    if(lastbuyopentime<Time[0])tpb=0;else tpb=1;
    if(lastsellopentime<Time[0])tps=0;else tps=1;
    }
    if(tradesperbar!=1 && bc!=Bars){tpb=0;tps=0;bc=Bars;}

    if(time!=Time[0] || shift==0){
    double mau=iMA(NULL,0,maperiod,0,MODE_SMMA,PRICE_HIGH,shift);
    double mad=iMA(NULL,0,maperiod,0,MODE_SMMA,PRICE_LOW,shift);
    double maua=iMA(NULL,0,maperiod,0,MODE_SMMA,PRICE_HIGH,shift+1);
    double mada=iMA(NULL,0,maperiod,0,MODE_SMMA,PRICE_LOW,shift+1);

    double smu=iCustom(NULL,0,”smC4Scalper Candles_v3.1″,3,shift);
    double smd=iCustom(NULL,0,”smC4Scalper Candles_v3.1″,2,shift);

    double macu=iCustom(NULL,0,”MA in Color_wAppliedPrice”,MAPeriod,MAType,MAAppliedPrice,1,shift);
    double macd=iCustom(NULL,0,”MA in Color_wAppliedPrice”,MAPeriod,MAType,MAAppliedPrice,2,shift);
    double macua=iCustom(NULL,0,”MA in Color_wAppliedPrice”,MAPeriod,MAType,MAAppliedPrice,1,shift+1);
    double macda=iCustom(NULL,0,”MA in Color_wAppliedPrice”,MAPeriod,MAType,MAAppliedPrice,2,shift+1);

    double macdi=iCustom(NULL,0,”MACD Alert”,FastEMA,SlowEMA,SignalSMA,0,shift);
    double macdia=iCustom(NULL,0,”MACD Alert”,FastEMA,SlowEMA,SignalSMA,0,shift+1);
    double macdiu=iCustom(NULL,0,”MACD Alert”,FastEMA,SlowEMA,SignalSMA,2,shift);
    double macdid=iCustom(NULL,0,”MACD Alert”,FastEMA,SlowEMA,SignalSMA,3,shift);
    time=Time[0];
    }
    bool buy=false;
    bool sell=false;

    if(
    (smc4scalperfilter==false || (smc4scalperfilter && smu>smd))
    && (mainappliedpricefilter==false || (mainappliedpricefilter && macu>macua && macu!=EMPTY_VALUE))
    && (machannelsignal==false || (machannelsignal && Open[shift+1]<maua && Open[shift]>mau))
    && (macdfilter==false || (macdfilter && macdi>macdia && macdiu==macdi))
    && (changedirection==false || (changedirection && continuebuy))
    ){
    if(reversesignals)sell=true;else buy=true;
    continuebuy=false;
    continuesell=true;
    if(autosl){stoploss=(Ask-mad)/pt;if(stoploss<stoplevel)stoploss=stoplevel;}
    }

    if(
    (smc4scalperfilter==false || (smc4scalperfilter && smu<smd))
    && (mainappliedpricefilter==false || (mainappliedpricefilter && macd<macda && macda!=EMPTY_VALUE))
    && (machannelsignal==false || (machannelsignal && Open[shift+1]>mada && Open[shift]<mad))
    && (macdfilter==false || (macdfilter && macdi<macdia && macdid==macdi))
    && (changedirection==false || (changedirection && continuesell))
    ){
    if(reversesignals)buy=true;else sell=true;
    continuebuy=true;
    continuesell=false;
    if(autosl){stoploss=(mau-Ask)/pt;if(stoploss<stoplevel)stoploss=stoplevel;}
    }

    //Comment(“\nhau = “+DoubleToStr(hau,5),”\nhad = “+DoubleToStr(had,5));

    if((oppositeclose && sell))closebuy();
    if((oppositeclose && buy))closesell();

    if(hidetp || hidesl){hideclosesell();hideclosebuy();}

    //if(usetimeout){closebuytime();closeselltime();}

    /*
    lastbuylot=0;
    lastselllot=0;
    lastorder=0;

    if(OrdersHistoryTotal()>0){
    for(i=0;i<=OrdersHistoryTotal();i++){
    OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
    lastprofit=OrderProfit();
    lastlot=OrderLots();
    if(OrderType()==OP_BUY){
    lastbuyprofit=OrderProfit();
    lastbuylot=OrderLots();
    lastorder=1;
    }
    if(OrderType()==OP_SELL){
    lastsellprofit=OrderProfit();
    lastselllot=OrderLots();
    lastorder=2;
    }
    }
    }
    }
    mlots=0;
    if(martingale && lastprofit<0)mlots=lastlot*multiplier;else mlots=lots;
    */

    if((Ask-Bid)>maxspread*mt*pt)return(0);
    if((count(OP_BUY)+count(OP_SELL))>=maxtrades)return(0);
    if(checktime())return(0);

    if(mm /*&& (martingale==false || (martingale && lastprofit>=0))*/)lots=lotsoptimized();

    int expire=0;
    if(expiration>0)expire=TimeCurrent()+(expiration*60)-5;

    ticket=0;
    number=0;
    if(buy && tpb<tradesperbar){
    /*if(martingale)ilots=mlots;else*/ ilots=lots;
    if(ecn==false){
    while(ticket<=0 && number<tries){
    while(!IsTradeAllowed())Sleep(5000);
    RefreshRates();
    ticket=open(OP_BUY,ilots,Ask,stoploss,takeprofit,expire,Blue);
    if(ticket<0){
    //Print(“Error opening BUY order! “,errordescription(GetLastError()));
    number++;
    }
    }
    }
    if(ecn){
    while(ticket<=0 && number<tries){
    while(!IsTradeAllowed())Sleep(5000);
    RefreshRates();
    ticket=open(OP_BUY,ilots,Ask,0,0,expire,Blue);
    if(ticket<0){
    //Print(“Error opening BUY order! “,errordescription(GetLastError()));
    number++;
    }
    }
    createlstoploss(stoploss);
    createltakeprofit(takeprofit);
    }
    if(ticket<=0){/*Print(“Error Occured : “+errordescription(GetLastError()));*/}else tpb++;
    }
    ticket=0;
    if(sell && tps<tradesperbar){
    /*if(martingale)ilots=mlots;else*/ ilots=lots;
    if(ecn==false){
    while(ticket<=0 && number<tries){
    while(!IsTradeAllowed())Sleep(5000);
    RefreshRates();
    ticket=open(OP_SELL,ilots,Bid,stoploss,takeprofit,expire,Red);
    if(ticket<0){
    //Print(“Error opening BUY order! “,errordescription(GetLastError()));
    number++;
    }
    }
    }
    if(ecn){
    while(ticket<=0 && number<tries){
    while(!IsTradeAllowed())Sleep(5000);
    RefreshRates();
    ticket=open(OP_SELL,ilots,Bid,0,0,expire,Red);
    if(ticket<0){
    //Print(“Error opening BUY order! “,errordescription(GetLastError()));
    number++;
    }
    }
    createsstoploss(stoploss);
    createstakeprofit(takeprofit);
    }
    if(ticket<=0){/*Print(“Error Occured : “+errordescription(GetLastError()));*/}else tps++;
    }
    if(ecn){
    createlstoploss(stoploss);
    createltakeprofit(takeprofit);
    createsstoploss(stoploss);
    createstakeprofit(takeprofit);
    }
    return(0);
    }

    //|———open

    int open(int type,double lots,double price,double stoploss,double takeprofit,int expire,color clr){
    int ticket=0;
    if(lots<minlot)lots=minlot;
    if(lots>maxlot)lots=maxlot;
    if(type==OP_BUY || type==OP_BUYSTOP || type==OP_BUYLIMIT){
    if(hidesl==false && stoploss>0){sl=price-stoploss*pt;}else{sl=0;}
    if(hidetp==false && takeprofit>0){tp=price+takeprofit*pt;}else{tp=0;}
    }
    if(type==OP_SELL || type==OP_SELLSTOP || type==OP_SELLLIMIT){
    if(hidesl==false && stoploss>0){sl=price+stoploss*pt;}else{sl=0;}
    if(hidetp==false && takeprofit>0){tp=price-takeprofit*pt;}else{tp=0;}
    }
    ticket=OrderSend(Symbol(),type,NormalizeDouble(lots,lotdigits),NormalizeDouble(price,dg),slippage*mt,sl,tp,comment+” “+DoubleToStr(magic,0),magic,expire,clr);
    return(ticket);
    }

    //|———lots optimized

    double lotsoptimized(){
    double lot;
    if(stoploss>0)lot=AccountBalance()*(risk/100)/(stoploss*pt/MarketInfo(Symbol(),MODE_TICKSIZE)*MarketInfo(Symbol(),MODE_TICKVALUE));
    else lot=NormalizeDouble((AccountBalance()/lotsize)*minlot*risk,lotdigits);
    //lot=AccountFreeMargin()/(100.0*(NormalizeDouble(MarketInfo(Symbol(),MODE_MARGINREQUIRED),4)+5.0)/risk)-0.05;
    return(lot);
    }

    //|———time filter

    bool checktime(){
    if(TimeCurrent()<win[TimeYear(TimeCurrent())-1999] && TimeCurrent()>sum[TimeYear(TimeCurrent())-1999])gmtshift=summergmtshift;
    else gmtshift=wintergmtshift;

    string svrdate=Year()+”.”+Month()+”.”+Day();

    if(mondayfilter){
    nmondayhour=mondayhour+(gmtshift);if(nmondayhour>23)nmondayhour=nmondayhour-24;
    if(nmondayhour<10)imondayhour=”0″+nmondayhour;
    if(nmondayhour>9)imondayhour=nmondayhour;
    if(mondayminute<10)imondayminute=”0″+mondayminute;
    if(mondayminute>9)imondayminute=mondayminute;
    tmonday=StrToTime(svrdate+” “+imondayhour+”:”+imondayminute);
    }
    if(weekfilter){
    nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24;
    if(nstarthour<10)istarthour=”0″+nstarthour;
    if(nstarthour>9)istarthour=nstarthour;
    if(startminute<10)istartminute=”0″+startminute;
    if(startminute>9)istartminute=startminute;
    tstart=StrToTime(svrdate+” “+istarthour+”:”+istartminute);

    nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24;
    if(endhour<10)iendhour=”0″+nendhour;
    if(endhour>9)iendhour=nendhour;
    if(endminute<10)iendminute=”0″+endminute;
    if(endminute>9)iendminute=endminute;
    tend=StrToTime(svrdate+” “+iendhour+”:”+iendminute);
    }
    if(fridayfilter){
    nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24;
    if(nfridayhour<10)ifridayhour=”0″+nfridayhour;
    if(nfridayhour>9)ifridayhour=nfridayhour;
    if(fridayminute<10)ifridayminute=”0″+fridayminute;
    if(fridayminute>9)ifridayminute=fridayminute;
    tfriday=StrToTime(svrdate+” “+ifridayhour+”:”+ifridayminute);
    }
    if((weekfilter && (nstarthour<=nendhour && TimeCurrent()<tstart || TimeCurrent()>tend) || (nstarthour>nendhour && TimeCurrent()<tstart && TimeCurrent()>tend))
    || (tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday) || (mondayfilter && DayOfWeek()==1 && TimeCurrent()<tmonday))return(true);
    return(false);
    }

    //|———counter

    int count(int type){
    cnt=0;
    if(OrdersTotal()>0){
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==magic)cnt++;
    }
    return(cnt);
    }
    }

    //|———close

    void closebuy(){
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal()-1;i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY){
    OrderClose(OrderTicket(),OrderLots(),Bid,slippage*mt);
    }
    }
    }
    }

    void closesell(){
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal()-1;i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL){
    OrderClose(OrderTicket(),OrderLots(),Ask,slippage*mt);
    }
    }
    }
    }

    void hideclosebuy(){
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal()-1;i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY
    && (hidesl && stoploss>0 && OrderProfit()<=(-1)*stoploss*OrderLots()*10-MarketInfo(Symbol(),MODE_SPREAD)*OrderLots()*10/mt)
    || (hidetp && takeprofit>0 && OrderProfit()>=takeprofit*OrderLots()*10)){
    OrderClose(OrderTicket(),OrderLots(),Bid,slippage*mt);
    }
    }
    }
    }

    void hideclosesell(){
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal()-1;i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL
    && (hidesl && stoploss>0 && OrderProfit()<=(-1)*stoploss*OrderLots()*10-MarketInfo(Symbol(),MODE_SPREAD)*OrderLots()*10/mt)
    || (hidetp && takeprofit>0 && OrderProfit()>=takeprofit*OrderLots()*10)){
    OrderClose(OrderTicket(),OrderLots(),Ask,slippage*mt);
    }
    }
    }
    }

    /*
    void closebuytime(){
    tradeprofit=0;
    tradetime=0;
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY){
    tradeprofit=NormalizeDouble(OrderClosePrice()-OrderOpenPrice(),dg);
    tradetime=TimeCurrent()-OrderOpenTime();
    if((tradeprofit>=target1*pt && tradetime>timeout1*60 && tradetime<timeout2*60) || (tradeprofit>=target2*pt && tradetime>timeout2*60 && tradetime<timeout3*60)
    || (tradeprofit>=target3*pt && tradetime>timeout3*60 && tradetime<timeout4*60) || (tradeprofit>=target4*pt && tradetime>timeout4*60 && tradetime<timeout5*60)
    || (tradeprofit>=target5*pt && tradetime>timeout5*60 && tradetime<timeout6*60) || (tradeprofit>=target6*pt && tradetime>timeout6*60 && tradetime<timeout7*60)
    || (tradeprofit>=target7*pt && tradetime>timeout7*60)){
    OrderClose(OrderTicket(),OrderLots(),Bid,slippage*mt);
    }
    }
    }
    }
    }

    void closeselltime(){
    tradeprofit=0;
    tradetime=0;
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL){
    tradeprofit=NormalizeDouble(OrderClosePrice()-OrderOpenPrice(),dg);
    tradetime=TimeCurrent()-OrderOpenTime();
    if((tradeprofit>=target1*pt && tradetime>timeout1*60 && tradetime<timeout2*60) || (tradeprofit>=target2*pt && tradetime>timeout2*60 && tradetime<timeout3*60)
    || (tradeprofit>=target3*pt && tradetime>timeout3*60 && tradetime<timeout4*60) || (tradeprofit>=target4*pt && tradetime>timeout4*60 && tradetime<timeout5*60)
    || (tradeprofit>=target5*pt && tradetime>timeout5*60 && tradetime<timeout6*60) || (tradeprofit>=target6*pt && tradetime>timeout6*60 && tradetime<timeout7*60)
    || (tradeprofit>=target7*pt && tradetime>timeout7*60)){
    OrderClose(OrderTicket(),OrderLots(),Ask,slippage*mt);
    }
    }
    }
    }
    }*/

    //|———breakeven

    void movebreakeven(double breakevengain,double breakeven){
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
    if(OrderType()==OP_BUY){
    if(NormalizeDouble((Bid-OrderOpenPrice()),dg)>=NormalizeDouble(breakevengain*pt,dg)){
    if((NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),dg)<NormalizeDouble(breakeven*pt,dg)) || OrderStopLoss()==0){
    OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+breakeven*pt,dg),OrderTakeProfit(),0,Blue);
    return(0);
    }
    }
    }
    else{
    if(NormalizeDouble((OrderOpenPrice()-Ask),dg)>=NormalizeDouble(breakevengain*pt,dg)){
    if((NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),dg)<NormalizeDouble(breakeven*pt,dg)) || OrderStopLoss()==0){
    OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-breakeven*pt,dg),OrderTakeProfit(),0,Red);
    return(0);
    }
    }
    }
    }
    }
    }
    }

    //|———trailingstop

    void movetrailingstop(double trailingstart,double trailingstop){
    RefreshRates();
    if(OrdersTotal()>0){
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
    if(OrderType()==OP_BUY){
    if(NormalizeDouble(Ask,dg)>NormalizeDouble(OrderOpenPrice()+trailingstart*pt,dg)
    && NormalizeDouble(OrderStopLoss(),dg)<NormalizeDouble(Bid-(trailingstop+trailingstep)*pt,dg)){
    OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-trailingstop*pt,dg),OrderTakeProfit(),0,Blue);
    return(0);
    }
    }
    else{
    if(NormalizeDouble(Bid,dg)<NormalizeDouble(OrderOpenPrice()-trailingstart*pt,dg)
    && (NormalizeDouble(OrderStopLoss(),dg)>(NormalizeDouble(Ask+(trailingstop+trailingstep)*pt,dg))) || (OrderStopLoss()==0)){
    OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+trailingstop*pt,dg),OrderTakeProfit(),0,Red);
    return(0);
    }
    }
    }
    }
    }
    }
    /*
    //|———trailingprofit

    void movetrailingprofit(double trailingstart,double trailingprofit){
    RefreshRates();
    for(i=OrdersTotal();i>=0;i–){
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
    if(OrderSymbol()==Symbol()&& OrderMagicNumber()==magic){
    if(OrderType()==OP_BUY){
    if(NormalizeDouble(Bid-OrderOpenPrice(),dg)<=NormalizeDouble((-1)*trailingstart*pt,dg)){
    if(NormalizeDouble(OrderTakeProfit(),dg)>NormalizeDouble(Bid+(trailingprofit+trailingstep)*pt,dg) || NormalizeDouble(OrderTakeProfit(),dg)==0){
    OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Bid+trailingprofit*pt,dg),0,Blue);
    }
    }
    }
    if(OrderType()==OP_SELL){
    if(NormalizeDouble(OrderOpenPrice()-Ask,dg)<=NormalizeDouble((-1)*trailingstart*pt,dg)){
    if(NormalizeDouble(OrderTakeProfit(),dg)<NormalizeDouble(Ask-(trailingprofit+trailingstep)*pt,dg)){
    OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Ask-trailingprofit*pt,dg),0,Red);
    }
    }
    }
    }
    }
    }
    }
    */
    void createlstoploss(double stoploss){
    RefreshRates();
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
    if(OrderType()==OP_BUY){
    if(OrderStopLoss()==0){
    OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask-stoploss*pt,dg),OrderTakeProfit(),0,Red);
    return(0);
    }
    }
    }
    }
    }

    void createsstoploss(double stoploss){
    RefreshRates();
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
    if(OrderType()==OP_SELL){
    if(OrderStopLoss()==0){
    OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid+stoploss*pt,dg),OrderTakeProfit(),0,Red);
    return(0);
    }
    }
    }
    }
    }

    void createltakeprofit(double takeprofit){
    RefreshRates();
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
    if(OrderType()==OP_BUY){
    if(OrderTakeProfit()==0){
    OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Ask+takeprofit*pt,dg),0,Red);
    return(0);
    }
    }
    }
    }
    }

    void createstakeprofit(double takeprofit){
    RefreshRates();
    int total=OrdersTotal();
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
    if(OrderType()==OP_SELL){
    if(OrderTakeProfit()==0){
    OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(Bid-takeprofit*pt,dg),0,Red);
    return(0);
    }
    }
    }
    }
    }
    /*
    //|———basket

    bool closebasketpercent(double profit,double loss){
    double ipf,ilo;
    ipf=profit*(0.01*AccountBalance());
    ilo=loss*(0.01*AccountBalance());
    cb=AccountEquity()-AccountBalance();
    if(cb>=ipf || cb<=(ilo*(-1)))return(1);
    return(0);
    }

    //|———delete

    void delete(int type){
    if(OrdersTotal()>0){
    for(i=OrdersTotal();i>=0;i–){
    OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==type){
    OrderDelete(OrderTicket());
    }
    }
    }
    }*/
    /*
    //|———error

    string errordescription(int code){
    string error;
    switch(code){
    case 0:
    case 1:error=”no error”;break;
    case 2:error=”common error”;break;
    case 3:error=”invalid trade parameters”;break;
    case 4:error=”trade server is busy”;break;
    case 5:error=”old version of the client terminal”;break;
    case 6:error=”no connection with trade server”;break;
    case 7:error=”not enough rights”;break;
    case 8:error=”too frequent requests”;break;
    case 9:error=”malfunctional trade operation”;break;
    case 64:error=”account disabled”;break;
    case 65:error=”invalid account”;break;
    case 128:error=”trade timeout”;break;
    case 129:error=”invalid price”;break;
    case 130:error=”invalid stops”;break;
    case 131:error=”invalid trade volume”;break;
    case 132:error=”market is closed”;break;
    case 133:error=”trade is disabled”;break;
    case 134:error=”not enough money”;break;
    case 135:error=”price changed”;break;
    case 136:error=”off quotes”;break;
    case 137:error=”broker is busy”;break;
    case 138:error=”requote”;break;
    case 139:error=”order is locked”;break;
    case 140:error=”long positions only allowed”;break;
    case 141:error=”too many requests”;break;
    case 145:error=”modification denied because order too close to market”;break;
    case 146:error=”trade context is busy”;break;
    case 4000:error=”no error”;break;
    case 4001:error=”wrong function pointer”;break;
    case 4002:error=”array index is out of range”;break;
    case 4003:error=”no memory for function call stack”;break;
    case 4004:error=”recursive stack overflow”;break;
    case 4005:error=”not enough stack for parameter”;break;
    case 4006:error=”no memory for parameter string”;break;
    case 4007:error=”no memory for temp string”;break;
    case 4008:error=”not initialized string”;break;
    case 4009:error=”not initialized string in array”;break;
    case 4010:error=”no memory for array\’ string”;break;
    case 4011:error=”too long string”;break;
    case 4012:error=”remainder from zero divide”;break;
    case 4013:error=”zero divide”;break;
    case 4014:error=”unknown command”;break;
    case 4015:error=”wrong jump (never generated error)”;break;
    case 4016:error=”not initialized array”;break;
    case 4017:error=”dll calls are not allowed”;break;
    case 4018:error=”cannot load library”;break;
    case 4019:error=”cannot call function”;break;
    case 4020:error=”expert function calls are not allowed”;break;
    case 4021:error=”not enough memory for temp string returned from function”;break;
    case 4022:error=”system is busy (never generated error)”;break;
    case 4050:error=”invalid function parameters count”;break;
    case 4051:error=”invalid function parameter value”;break;
    case 4052:error=”string function internal error”;break;
    case 4053:error=”some array error”;break;
    case 4054:error=”incorrect series array using”;break;
    case 4055:error=”custom indicator error”;break;
    case 4056:error=”arrays are incompatible”;break;
    case 4057:error=”global variables processing error”;break;
    case 4058:error=”global variable not found”;break;
    case 4059:error=”function is not allowed in testing mode”;break;
    case 4060:error=”function is not confirmed”;break;
    case 4061:error=”send mail error”;break;
    case 4062:error=”string parameter expected”;break;
    case 4063:error=”integer parameter expected”;break;
    case 4064:error=”double parameter expected”;break;
    case 4065:error=”array as parameter expected”;break;
    case 4066:error=”requested history data in update state”;break;
    case 4099:error=”end of file”;break;
    case 4100:error=”some file error”;break;
    case 4101:error=”wrong file name”;break;
    case 4102:error=”too many opened files”;break;
    case 4103:error=”cannot open file”;break;
    case 4104:error=”incompatible access to a file”;break;
    case 4105:error=”no order selected”;break;
    case 4106:error=”unknown symbol”;break;
    case 4107:error=”invalid price parameter for trade function”;break;
    case 4108:error=”invalid ticket”;break;
    case 4109:error=”trade is not allowed”;break;
    case 4110:error=”longs are not allowed”;break;
    case 4111:error=”shorts are not allowed”;break;
    case 4200:error=”object is already exist”;break;
    case 4201:error=”unknown object property”;break;
    case 4202:error=”object is not exist”;break;
    case 4203:error=”unknown object type”;break;
    case 4204:error=”no object name”;break;
    case 4205:error=”object coordinates error”;break;
    case 4206:error=”no specified subwindow”;break;
    default:error=”unknown error”;
    }
    return(error);
    }
    */

    #20294

    Interesting.. I have read more about this on forexfactory. http://www.forexfactory.com/showthread.php?t=513860

    Maybe someone could help to create the code what is using for mt4. In post 11 you can download the file.

    #25036

    Possibly of interest, I found that the heikin-ashi on range ( https://www.prorealcode.com/prorealtime-indicators/heiken-ashi-on-range-bar/ ) will successfully overlay HA candles on a renko chart. Each candle is horizontally sized according to the time necessary (i.e. a renko move taking more time will show a wider candle, while a faster renko move will show a narrower candle).

    #25052
    211

    Cool, Thanks!

Viewing 6 posts - 1 through 6 (of 6 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login