[help] Still unable to convert this MQ4 indicator to Thinkscript - ThinkOrSwim Programming | futures io social day trading
futures io futures trading


[help] Still unable to convert this MQ4 indicator to Thinkscript
Updated: Views / Replies:877 / 0
Created: by Ardian1899 Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

[help] Still unable to convert this MQ4 indicator to Thinkscript

  #1 (permalink)
Trading Apprentice
Malang, East Java - Indonesia
 
Futures Experience: Intermediate
Platform: MetaTrader Thinkorswim
Favorite Futures: GBPUSD
 
Posts: 3 since Jul 2014
Thanks: 1 given, 1 received

[help] Still unable to convert this MQ4 indicator to Thinkscript

Hi All,

If this ever discussed before, please share me the link, thank you.

I've try to convert this MT4 indicator to Thinkscript. I'm stucked on the trend recognition codes, please help.

 
Code
      for(i=limit, r=Bars-i-1; i>=0; i--,r++)
      {
         int y = iBarShift(NULL,timeFrame,Time[i]);
         double rhigh = iHigh(NULL,timeFrame,iHighest(NULL,timeFrame,MODE_HIGH,TradePeriod,y+1));
         double shigh = iHigh(NULL,timeFrame,iHighest(NULL,timeFrame,MODE_HIGH,StopPeriod ,y+1));
         double rlow  =  iLow(NULL,timeFrame,iLowest(NULL,timeFrame,MODE_LOW,TradePeriod,y+1));
         double slow  =  iLow(NULL,timeFrame,iLowest(NULL,timeFrame,MODE_LOW,StopPeriod ,y+1));
         double close = iClose(NULL,timeFrame,y);
       
         trend[r] = trend[r-1];  
            if(close > rhigh) trend[r] =  1;
            if(close < rlow)  trend[r] = -1;
      
            ExtMapBuffer1[i] = EMPTY_VALUE;
            ExtMapBuffer2[i] = EMPTY_VALUE;
            ExtMapBuffer3[i] = EMPTY_VALUE;
            ExtMapBuffer4[i] = EMPTY_VALUE;
            dotTup[i]        = EMPTY_VALUE;
            dotTdn[i]        = EMPTY_VALUE;
            dotSup[i]        = EMPTY_VALUE;
            dotSdn[i]        = EMPTY_VALUE;
         
            if(trend[r] == 1) 
            {
               ExtMapBuffer1[i] = rlow;
               ExtMapBuffer3[i] = slow;
               if (trend[r]!=trend[r-1])
               {
                  dotTup[i] = rlow;
                  dotSup[i] = slow;
               }
            }               
            if(trend[r] == -1) 
            {
               ExtMapBuffer2[i] = rhigh;
               ExtMapBuffer4[i] = shigh;
               if (trend[r]!=trend[r-1])
               {
                  dotTdn[i] = rhigh;
                  dotSdn[i] = shigh;
               }
            }
     }

Full Code:
 
Code
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 DarkSlateGray
#property indicator_color4 DarkSlateGray
#property indicator_color5 DodgerBlue
#property indicator_color6 Red
#property indicator_color7 DodgerBlue
#property indicator_color8 Red
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#property indicator_width7 1
#property indicator_width8 1
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT

extern string TimeFrame       = "Current time frame";
extern int    TradePeriod     = 11;
extern int    StopPeriod      = 6;
extern bool   alertsOn        = true;
extern bool   alertsOnCurrent = true;
extern bool   alertsMessage   = true;
extern bool   alertsSound     = false;
extern bool   alertsNotify    = true;
extern bool   alertsEmail     = true;
extern string soundFile       = "alert2.wav"; 

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double dotTup[];
double dotTdn[];
double dotSup[];
double dotSdn[];

string indicatorFileName;
bool   returnBars;
int    timeFrame;

//------------------------------------------------------------------
//
//------------------------------------------------------------------
int init()
{
   SetIndexBuffer(0,ExtMapBuffer1); SetIndexLabel(0,"Upper Channel");
   SetIndexBuffer(1,ExtMapBuffer2); SetIndexLabel(1,"Lower Channel");
   SetIndexBuffer(2,ExtMapBuffer3); SetIndexLabel(2,"Phantom Up Channel");
   SetIndexBuffer(3,ExtMapBuffer4); SetIndexLabel(3,"Phantom Down Channel");
   SetIndexBuffer(4,dotTup); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,159);
   SetIndexBuffer(5,dotTdn); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,159);
   SetIndexBuffer(6,dotSup); SetIndexStyle(6,DRAW_ARROW); SetIndexArrow(6,159);
   SetIndexBuffer(7,dotSdn); SetIndexStyle(7,DRAW_ARROW); SetIndexArrow(7,159);
      indicatorFileName = WindowExpertName();
      returnBars        = TimeFrame=="returnBars";     if (returnBars)     { return(0); }
      timeFrame         = stringToTimeFrame(TimeFrame);
   IndicatorShortName("Turtle Channel ("+ TradePeriod +")");
   return(0);
  }
//------------------------------------------------------------------
//
//------------------------------------------------------------------
double trend[];
int start()
{
   int i,r,counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(Bars-counted_bars,Bars-1);
           if (returnBars) { ExtMapBuffer1[0] = MathMin(limit+1,Bars-1); return(0); }
           if (timeFrame!=Period()) limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));
           if (ArraySize(trend)!=Bars) ArrayResize(trend,Bars);

   //
   //
   //
   //
   //

      for(i=limit, r=Bars-i-1; i>=0; i--,r++)
      {
         int y = iBarShift(NULL,timeFrame,Time[i]);
         double rhigh = iHigh(NULL,timeFrame,iHighest(NULL,timeFrame,MODE_HIGH,TradePeriod,y+1));
         double shigh = iHigh(NULL,timeFrame,iHighest(NULL,timeFrame,MODE_HIGH,StopPeriod ,y+1));
         double rlow  =  iLow(NULL,timeFrame,iLowest(NULL,timeFrame,MODE_LOW,TradePeriod,y+1));
         double slow  =  iLow(NULL,timeFrame,iLowest(NULL,timeFrame,MODE_LOW,StopPeriod ,y+1));
         double close = iClose(NULL,timeFrame,y);
       
         trend[r] = trend[r-1];  
            if(close > rhigh) trend[r] =  1;
            if(close < rlow)  trend[r] = -1;
      
            ExtMapBuffer1[i] = EMPTY_VALUE;
            ExtMapBuffer2[i] = EMPTY_VALUE;
            ExtMapBuffer3[i] = EMPTY_VALUE;
            ExtMapBuffer4[i] = EMPTY_VALUE;
            dotTup[i]        = EMPTY_VALUE;
            dotTdn[i]        = EMPTY_VALUE;
            dotSup[i]        = EMPTY_VALUE;
            dotSdn[i]        = EMPTY_VALUE;
         
            if(trend[r] == 1) 
            {
               ExtMapBuffer1[i] = rlow;
               ExtMapBuffer3[i] = slow;
               if (trend[r]!=trend[r-1])
               {
                  dotTup[i] = rlow;
                  dotSup[i] = slow;
               }
            }               
            if(trend[r] == -1) 
            {
               ExtMapBuffer2[i] = rhigh;
               ExtMapBuffer4[i] = shigh;
               if (trend[r]!=trend[r-1])
               {
                  dotTdn[i] = rhigh;
                  dotSdn[i] = shigh;
               }
            }
     }
   manageAlerts();
   return(0);
}

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------


string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));
                                                      return(Period());
}


string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int tchar = StringGetChar(s, length);
         if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256))
                     s = StringSetChar(s, length, tchar - 32);
         else if(tchar > -33 && tchar < 0)
                     s = StringSetChar(s, length, tchar + 224);
   }
   return(s);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

void manageAlerts()
{
   if (alertsOn)
   {
      if (alertsOnCurrent)
           int whichBar = 0;
      else     whichBar = 1; whichBar = Bars-iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar))-1;
      if (trend[whichBar] != trend[whichBar-1])
      {
            if (trend[whichBar] == 1) doAlert(whichBar,"Buy");
            if (trend[whichBar] ==-1) doAlert(whichBar,"Sell");
      }         
    }         
}   

void doAlert(int forBar, string doWhat)
{
   static string   previousAlert="nothing";
   static datetime previousTime;
   string message;
   
      if (previousAlert != doWhat || previousTime != Time[forBar]) {
          previousAlert  = doWhat;
          previousTime   = Time[forBar];

          message =  StringConcatenate(Symbol()," ",timeFrameToString(timeFrame)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," TheTurtleTradingChannel ",doWhat);
             if (alertsMessage) Alert(message);
             if (alertsNotify)  SendNotification(StringConcatenate(Symbol(), Period() ," TheTurtleTradingChannel " +" "+message));
             if (alertsEmail)   SendMail(StringConcatenate(Symbol()," TheTurtleTradingChannel "),message);
             if (alertsSound)   PlaySound(soundFile);
      }
}
This is what I do so far:
 
Code
input TimeFrame       = AggregationPeriod.HOUR;
input TradePeriod     = 11;
input StopPeriod      = 6;

def na=Double.nan; 

def hhi = high(period = TimeFrame);
def llo = low(period = TimeFrame);
def ccl = close(period = TimeFrame);

def rhigh = Highest(hhi, TradePeriod);
def shigh = Highest(hhi, StopPeriod);
def rlow = Lowest(llo, TradePeriod);
def slow = Lowest(llo, StopPeriod);

def trend = if (ccl > rhigh[1]) then 1 else if (ccl < llo[1]) then -1 else 0;

def ext1 =  if trend == 1 then rlow else if trend== -1 then rhigh else na;

plot ExtMapBuffer1 = if ext1== na then ext1[1] else ext1;
We can forget the alerts for now. Any help will be greatly appreciated. Thank you

Reply With Quote

Reply



futures io > > > > > [help] Still unable to convert this MQ4 indicator to Thinkscript

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Easy Language code into Thinkscript sboarder13 ThinkOrSwim 20 November 22nd, 2016 01:47 AM
Unable to create instance of NinjaTrader.Indicator flipper26 NinjaTrader 3 August 6th, 2015 08:55 AM
Convert Easy Language code into Thinkscript study ckajrtx ThinkOrSwim 0 May 10th, 2014 02:07 AM
Convert MQ4 indicator to Ninjascript rookietrader11 NinjaTrader Programming 3 May 3rd, 2013 06:35 PM


All times are GMT -4. The time now is 07:48 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-17 in 0.06 seconds with 19 queries on phoenix via your IP 54.163.209.109