I am at my witts end, simple MACD Cross over strategy - Sierra Chart Programming | futures io social day trading
futures io futures trading


I am at my witts end, simple MACD Cross over strategy
Updated: Views / Replies:2,144 / 11
Created: by tomlryde 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
 

I am at my witts end, simple MACD Cross over strategy

  #1 (permalink)
Trading Apprentice
south bend, indiana
 
Futures Experience: Intermediate
Platform: sierra charts
Favorite Futures: futures
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

I am at my witts end, simple MACD Cross over strategy

Below is the complete code I wrote for a simple MACD Cross over strategy (long) I then reversed the logic on the Buy sell entry trigger to have a short Strategy. It does not work and I am at my witts end ready to pull my hair our. I need your help to look it over and tell me whereI went wrong on the sgort strategy. I hear how robust the Sierra Language is but it seems extremely tempermental. I have added one line of code to a strategy-- just on line and it completely changes the functionality of the code. It almost seems illogical. Someone please help me and clue me in.

Thanking you in advance

Tom

#include "sierrachart.h"



SCDLLName("9513help")

/********************************************************************
* *
* Tom MACD Long Combo *
* *
********************************************************************/

SCSFExport scsf_TomComboStrategyMACD(SCStudyInterfaceRef sc)
{
SCSubgraphRef BuyEntrySubgraph = sc.Subgraph[0];
SCSubgraphRef BuyExitSubgraph = sc.Subgraph[1];
SCSubgraphRef MACDData = sc.Subgraph[2];
SCSubgraphRef MovAvgOfMACD = sc.Subgraph[3];
SCSubgraphRef MACD = sc.Subgraph[4];
SCSubgraphRef MACDDiff = sc.Subgraph[5];




SCInputRef InputData = sc.Input[0];
SCInputRef FastLen = sc.Input[1];
SCInputRef SlowLen = sc.Input[2];
SCInputRef MACDLen = sc.Input[3];
SCInputRef MAType = sc.Input[4];
SCInputRef OffsetPercentInput = sc.Input[5];
SCInputRef Enabled = sc.Input[6];
SCInputRef TargetValue = sc.Input[9];
SCInputRef StopValue = sc.Input[10];
SCInputRef EntryLevelNum = sc.Input[11];




if (sc.SetDefaults)
{
// Set the configuration and defaults


sc.GraphName = "Tom MACD Strategy Long~";
sc.GraphRegion = 0; //Main chart region
sc.AutoLoop = 1;
sc.FreeDLL = 1;



BuyEntrySubgraph.Name = "Long Entry";
BuyEntrySubgraph.DrawStyle = DRAWSTYLE_ARROWUP;
BuyEntrySubgraph.PrimaryColor = RGB(19, 101, 236);
BuyEntrySubgraph.LineWidth = 2;
BuyEntrySubgraph.DrawZeros = false;


BuyExitSubgraph.Name = "Long Exit";
BuyExitSubgraph.DrawStyle = DRAWSTYLE_ARROWDOWN;
BuyExitSubgraph.PrimaryColor = RGB(140, 209, 242);
BuyExitSubgraph.LineWidth = 2;
BuyExitSubgraph.DrawZeros = false;

Enabled.Name = "Enabled";
Enabled.SetYesNo(0);

TargetValue.Name = "Target Value - Points - 1/4 point incriments";
TargetValue.SetFloat(20.0f);

StopValue.Name = "Stop Value - Points - 1/4 point incriments";
StopValue.SetFloat(1.25f);

/************MACD*****************/

InputData.Name = "Input Data";
InputData.SetInputDataIndex(SC_LAST);

FastLen.Name ="Fast Moving Average Length";
FastLen.SetInt(5);
FastLen.SetIntLimits(1,MAX_STUDY_LENGTH);

SlowLen.Name = "Slow Moving Average Length";
SlowLen.SetInt(30);
SlowLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MACDLen.Name = "MACD Moving Average Length";
MACDLen.SetInt(9);
MACDLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MAType.Name = "Moving Average Type";
MAType.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL);

EntryLevelNum.Name = "Entry Level Below -0- Line"; //inactive in this code
EntryLevelNum.SetFloat(-1.0f);



sc.Input[15].Name = "Contracts to Buy";
sc.Input[15].SetInt(1);
sc.Input[15].SetIntLimits(1, 100);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// order stuff
sc.AllowMultipleEntriesInSameDirection = false;
sc.SupportReversals = false;
sc.SendOrdersToTradeService = false;
sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
sc.SupportAttachedOrdersForTrading = false;
sc.CancelAllOrdersOnEntriesAndReversals= false;
sc.AllowEntryWithWorkingOrders = false;
sc.CancelAllWorkingOrdersOnExit = false;
sc.AllowOnlyOneTradePerBar = true;
sc.MaintainTradeStatisticsAndTradesData = true;

return;
}

int Order_qty = sc.Input[15].GetInt();
sc.MaximumPositionAllowed = Order_qty;

//Do Study calculations ~~~~~~~~~~~~~~~

// MACD

sc.MACD(sc.BaseDataIn[InputData.GetInputDataIndex()], MACDData, sc.Index, FastLen.GetInt(), SlowLen.GetInt(), MACDLen.GetInt(), MAType.GetInt());
MovAvgOfMACD[sc.Index] = MACD.Arrays[2][sc.Index];
MACDDiff[sc.Index] = MACD.Arrays[3][sc.Index];
float LowerLine = sc.Input[11].GetFloat();




if (!Enabled.GetYesNo())
return;

SCFloatArrayRef Last = sc.Close;

// Get the Internal Position data to be used for position exit processing.
s_SCPositionData InternalPositionData;
sc.GetInternalPosition(InternalPositionData) ;
float LastTradePrice = sc.Close[sc.Index];
// Create an s_SCNewOrder object.
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = Order_qty; //Total contracts
NewOrder.OrderType = SCT_MARKET;



int cnt=0;
int i = sc.Index;
int Result;
int status = sc.GetBarHasClosedStatus(sc.UpdateStartIndex);



if ((sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_BOTTOM) && (status == BHCS_BAR_HAS_CLOSED))
{Result = sc.BuyEntry(NewOrder); // Buy Long
if (Result > 0)
BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index];
}
else { // exit routine
if (InternalPositionData.PositionQuantity > 0 &&
((LastTradePrice <= InternalPositionData.AveragePrice - StopValue.GetFloat()) ||
(sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_TOP)
))

{Result = sc.BuyExit(NewOrder); //Sell Long
if(Result>0)
BuyExitSubgraph[sc.Index] = sc.High[sc.Index];

}
}

/*********************************** End Long Order Entry/Exit ****************/

}



/********************************************************************
* *
* Tom MACD short Combo *
* *
********************************************************************/

SCSFExport scsf_TomComboShortStrategyMACD(SCStudyInterfaceRef sc)
{
SCSubgraphRef SellEntrySubgraph = sc.Subgraph[0];
SCSubgraphRef SellExitSubgraph = sc.Subgraph[1];
SCSubgraphRef MACDData = sc.Subgraph[2];
SCSubgraphRef MovAvgOfMACD = sc.Subgraph[3];
SCSubgraphRef MACD = sc.Subgraph[4];
SCSubgraphRef MACDDiff = sc.Subgraph[5];




SCInputRef InputData = sc.Input[0];
SCInputRef FastLen = sc.Input[1];
SCInputRef SlowLen = sc.Input[2];
SCInputRef MACDLen = sc.Input[3];
SCInputRef MAType = sc.Input[4];
SCInputRef OffsetPercentInput = sc.Input[5];
SCInputRef Enabled = sc.Input[6];
SCInputRef TargetValue = sc.Input[9];
SCInputRef StopValue = sc.Input[10];
SCInputRef EntryLevelNum = sc.Input[11];




if (sc.SetDefaults)
{
// Set the configuration and defaults


sc.GraphName = "Tom MACD Short Strategy ";
sc.GraphRegion = 0; //Main chart region
sc.AutoLoop = 1;
sc.FreeDLL = 1;



SellEntrySubgraph.Name = "Long Entry";
SellEntrySubgraph.DrawStyle = DRAWSTYLE_ARROWUP;
SellEntrySubgraph.PrimaryColor = RGB(19, 101, 236);
SellEntrySubgraph.LineWidth = 2;
SellEntrySubgraph.DrawZeros = false;


SellExitSubgraph.Name = "Long Exit";
SellExitSubgraph.DrawStyle = DRAWSTYLE_ARROWDOWN;
SellExitSubgraph.PrimaryColor = RGB(140, 209, 242);
SellExitSubgraph.LineWidth = 2;
SellExitSubgraph.DrawZeros = false;

Enabled.Name = "Enabled";
Enabled.SetYesNo(0);

TargetValue.Name = "Target Value - Points - 1/4 point incriments";
TargetValue.SetFloat(20.0f);

StopValue.Name = "Stop Value - Points - 1/4 point incriments";
StopValue.SetFloat(1.25f);

/************MACD*****************/

InputData.Name = "Input Data";
InputData.SetInputDataIndex(SC_LAST);

FastLen.Name ="Fast Moving Average Length";
FastLen.SetInt(5);
FastLen.SetIntLimits(1,MAX_STUDY_LENGTH);

SlowLen.Name = "Slow Moving Average Length";
SlowLen.SetInt(30);
SlowLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MACDLen.Name = "MACD Moving Average Length";
MACDLen.SetInt(9);
MACDLen.SetIntLimits(1,MAX_STUDY_LENGTH);

MAType.Name = "Moving Average Type";
MAType.SetMovAvgType(MOVAVGTYPE_EXPONENTIAL);

EntryLevelNum.Name = "Entry Level Below -0- Line"; //inactive in this code
EntryLevelNum.SetFloat(-1.0f);



sc.Input[15].Name = "Contracts to Sell";
sc.Input[15].SetInt(1);
sc.Input[15].SetIntLimits(1, 100);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// order stuff
sc.AllowMultipleEntriesInSameDirection = false;
sc.SupportReversals = false;
sc.SendOrdersToTradeService = false;
sc.AllowOppositeEntryWithOpposingPositionOrOrders = false;
sc.SupportAttachedOrdersForTrading = false;
sc.CancelAllOrdersOnEntriesAndReversals= false;
sc.AllowEntryWithWorkingOrders = false;
sc.CancelAllWorkingOrdersOnExit = false;
sc.AllowOnlyOneTradePerBar = true;
sc.MaintainTradeStatisticsAndTradesData = true;

return;
}

int Order_qty = sc.Input[15].GetInt();
sc.MaximumPositionAllowed = Order_qty;

//Do Study calculations ~~~~~~~~~~~~~~~

// MACD

sc.MACD(sc.BaseDataIn[InputData.GetInputDataIndex()], MACDData, sc.Index, FastLen.GetInt(), SlowLen.GetInt(), MACDLen.GetInt(), MAType.GetInt());
MovAvgOfMACD[sc.Index] = MACD.Arrays[2][sc.Index];
MACDDiff[sc.Index] = MACD.Arrays[3][sc.Index];
float LowerLine = sc.Input[11].GetFloat();




if (!Enabled.GetYesNo())
return;

SCFloatArrayRef Last = sc.Close;

// Get the Internal Position data to be used for position exit processing.
s_SCPositionData InternalPositionData;
sc.GetInternalPosition(InternalPositionData) ;
float LastTradePrice = sc.Close[sc.Index];
// Create an s_SCNewOrder object.
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = Order_qty; //Total contracts
NewOrder.OrderType = SCT_MARKET;



int cnt=0;
int i = sc.Index;
int Result;
int status = sc.GetBarHasClosedStatus(sc.UpdateStartIndex);



if ((sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_TOP) && (status == BHCS_BAR_HAS_CLOSED))
{Result = sc.SellEntry(NewOrder); // Sell Long
if (Result > 0)
SellEntrySubgraph[sc.Index] = sc.High[sc.Index];
}
else { // exit routine
if (InternalPositionData.PositionQuantity > 0 &&
((LastTradePrice <= InternalPositionData.AveragePrice + StopValue.GetFloat()) ||
(sc.CrossOver( MACDData, MACDData.Arrays[2]) == CROSS_FROM_BOTTOM)
))

{Result = sc.SellExit(NewOrder); //Sell Long
if(Result>0)
SellExitSubgraph[sc.Index] = sc.Low[sc.Index];

}
}

/*********************************** End Short Order Entry/Exit ****************/

}

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Chicago Illinois USA
 
Futures Experience: Advanced
Platform: Ninja Trader
Broker/Data: IB
Favorite Futures: duh hammer!
 
wldman's Avatar
 
Posts: 2,077 since Aug 2011
Thanks: 971 given, 2,641 received

Don't flame me man...


I know exactly how you are feeling. But the answer is as simple as this. If the idiom wits' end, has just one t in it and you type two t's, a human knows exactly what you mean. However one character "off" in your script can ruin the entire script.

Get someone who uses that like @vegasfoster involved.

Second, if you have an editor on your platform, can you "find all, change all"? Go back and use that to retry the language you changed to create the sell side. Probably missing a single character or something real simple.

No worries though man, someone withe a fresh set of eyes will see it right away.

Reply With Quote
The following user says Thank You to wldman for this post:
 
  #4 (permalink)
Elite Member
Valdosta, GA. U.S.A
 
Futures Experience: Advanced
Platform: Sierra ,NT, TOS
Favorite Futures: 6E, 6J, CL, GC
 
Posts: 480 since Sep 2010
Thanks: 1,825 given, 466 received

withe

@ wildman.....withe
i could not help myself, seems this was intentional.
maybe one day i need to start learning how to program.
@ tomlryde.....i hope you can get this working like you want man.


Last edited by sandptrader; September 5th, 2013 at 09:24 PM. Reason: additional comment
Reply With Quote
The following 2 users say Thank You to sandptrader for this post:
 
  #5 (permalink)
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 received

It looks like you have two different strategies in the same file, is that correct? Cuz I'm pretty sure you can't do that. For example, you can't define two different subgraph[0] etc. in the same file. Create separate sections for long and short entry/exit criteria, but create one contiguous set of subgraphs, inputs, and configuration defaults.

Just a note on long/short entries and exits, if you are reversing, then you don't need to both exit the open position and enter the new position, just enter the new position and the open position will be closed automatically.

Computers do exactly what you tell them to do, so even a single character can screw up any program, regardless of the platform. The easiest way to code is to start with existing code that that's similar to what you want to do and then change it one line or one section at a time. Edit, compile, test, edit, compile, test, etc. Then you will know exactly where any problems lye.

Lemme know.

Reply With Quote
The following 2 users say Thank You to vegasfoster for this post:
 
  #6 (permalink)
Elite Member
Chicago Illinois USA
 
Futures Experience: Advanced
Platform: Ninja Trader
Broker/Data: IB
Favorite Futures: duh hammer!
 
wldman's Avatar
 
Posts: 2,077 since Aug 2011
Thanks: 971 given, 2,641 received

Thanks...

@vegasfoster

I may need a place to stay in South Bend or some game tickets. Pays to help a brother out.

DB

Reply With Quote
 
  #7 (permalink)
Trading Apprentice
south bend, indiana
 
Futures Experience: Intermediate
Platform: sierra charts
Favorite Futures: futures
 
Posts: 7 since Aug 2013
Thanks: 8 given, 1 received

Thanks for your reply. I failed to mention that I have two strategies posed above. the first is a long cross over which works just fine. the second is the exact same strategy only I reversed the logic on the cross over and it does not work. Listed is the complete code so anyone who wants to can load it and compile it to see what happens. So I am really frustrated.
Thanks again

Tom

Reply With Quote
The following user says Thank You to tomlryde for this post:
 
  #8 (permalink)
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 received

Ok, I can take a look at it tomorrow.

Reply With Quote
 
  #9 (permalink)
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 received


wldman View Post
@vegasfoster

I may need a place to stay in South Bend or some game tickets. Pays to help a brother out.

DB

Don't tell me, you dined and dashed again and have to lamb it. I can't protect you from the man anymore wildman. I just can't.

Reply With Quote
 
  #10 (permalink)
Elite Member
Chicago Illinois USA
 
Futures Experience: Advanced
Platform: Ninja Trader
Broker/Data: IB
Favorite Futures: duh hammer!
 
wldman's Avatar
 
Posts: 2,077 since Aug 2011
Thanks: 971 given, 2,641 received

Exactly...


@sandptrader

Way way back when the days of formal education where less of a distant fog, I had an English professor that inspired me to use items like the "withe" in my writing. I forgot the term, but doing that which I was using to make a point in context to reinforce and add levity, has a name.

You, being the first to notice or the first to point it out separate yourself from the crowd. You have a high level of acuity, that should be a great advantage in many things.

@vegasfoster is a crafty guy, although he does still live in his moms basement, I bet he can whip this issue in no time...come on vegas!

Reply With Quote
The following user says Thank You to wldman for this post:

Reply



futures io > > > > > I am at my witts end, simple MACD Cross over strategy

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
Cross Strategy Comunication quantismo NinjaTrader Programming 2 August 13th, 2013 02:38 AM
macd cross indicator wanted trdr NinjaTrader Programming 8 October 27th, 2012 04:40 PM
Multi Timeframe MA cross Strategy ryangillespie The Elite Circle 1 December 8th, 2011 06:31 PM
simple strategy to enter CCI cross +45/-45 emini_Holy_Grail NinjaTrader Programming 5 January 8th, 2011 10:48 AM
Looking for a simple MACD strategy. MACD Xover LONG, go LONG roshareid NinjaTrader Programming 2 April 11th, 2010 09:05 PM


All times are GMT -4. The time now is 07:19 AM.

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-18 in 0.17 seconds with 19 queries on phoenix via your IP 54.163.209.109