[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: HOW TO PLOT PRICE, MACD, STOCHASTIC ON ONE CHART?



PureBytes Links

Trading Reference Links

Yes you can pass the plot arrays as static variables.  That is what I  
would do, and I do it today.

I would pass every array and parameter needed by a plot command in  
static variables, and I mean everything.

That way the afl for the other panes is just a bunch of StaticVarGet()  
commands and a plot statement.  You will just need one param to tell  
it which of the plot data it should get.  You could append to the name  
of the static variables so that you don't even have to replicate  
anything in the plot code.  It can be completely generic.

BR,
Dennis


On Oct 15, 2009, at 11:15 AM, bistrader wrote:

> Keith - thanks.  I got a mess at this end with all of the variables  
> and all.  Need to print out, study and see if I can clean up.  Is  
> more time consuming and extensive (is that the word?) than I  
> thought.  At first, I thought, hey, I can just pass the final chart  
> array item such as Macd histogram and Stochastic.  Nope, can't do  
> just this it appears.  When I start over I will look at the action  
> == for exploration and backtest.  Thanks
>
> --- In amibroker@xxxxxxxxxxxxxxx, Keith McCombs <kmccombs@xxx> wrote:
>>
>> Dennis --
>> Your post looks like a major stride in the right direction.  I had
>> briefly tried something with StaticVar, but gave up after only a  
>> little
>> unsuccessful experimentation.  I will study what you have done and  
>> will
>> renew my effort.
>>
>> The necessity of setting parameters in all related panes, plus in AA,
>> and the repercussions of forgetting to make a change in one or more
>> locations, had for a very long time convinced me to not use Param()  
>> *at
>> all*, but to just change values in the editor.
>>
>> Thanks so much.
>>
>> Bistrader --
>> Maybe try something like this:
>> else if(status("action")== 5){ // backtest / optimize
>> // generic param fetch block
>> myControlParam1 = StaticVarGet( "myControlParam1" );
>> myControlParam2 = StaticVarGet( "myControlParam2" );
>> myControlParam3 = StaticVarGet( "myControlParam3" );
>> myControlParam4 = StaticVarGet( "myControlParam4" );
>> myControlParam5 = StaticVarGet( "myControlParam5" );
>>
>> -- Keith
>>
>> bistrader wrote:
>>>
>>>
>>> Dennis,
>>>
>>> Thank you and others for helping me along.
>>>
>>> Tried a similar approach. The afl would also have Buy and Sell logic
>>> so it can be used to provide backtest to get at trades and equity
>>> curve, and also to provide exploration to see buy and sell signals.
>>> Plus, the 3 charts or pans (Price, Macd Historgram and Stochastic).
>>> So, if I put, for example, the Macd Historgram code within the 'if'
>>> statement for that pane, then I the afl will not be able to  
>>> determine
>>> the buys and sells, based on price, Mach and Stochastic combined,  
>>> for
>>> backtesting and explorations. Correct??
>>>
>>> --- In amibroker@xxxxxxxxxxxxxxx <mailto:amibroker 
>>> %40yahoogroups.com>,
>>> Dennis Brown <see3d@> wrote:
>>>>
>>>> bistrader,
>>>>
>>>> If I were going to approach this problem of wanting to have the  
>>>> same
>>>> afl in each pane, with parameters shared by all, then the  
>>>> approach I
>>>> would use would be to structure the parameter code like below  
>>>> (tested):
>>>>
>>>> It does not matter what your chart ID is. Just insert x many panes
>>>> buy double clicking on the formula. Pull up the parameter window  
>>>> for
>>>> the price pane first and set it to Price, then do the same with the
>>>> others, selecting which data to plot. Finally pull up the param
>>>> window of the price pane again and you can control all panes from  
>>>> that
>>>> one window.
>>>>
>>>> Best regards,
>>>> Dennis
>>>>
>>>> _SECTION_BEGIN( "Pane Function" );
>>>> IAM = ParamList( "Pane Function", "None|Price|MACD|MACDH" );
>>>> _SECTION_END();
>>>>
>>>> if ( IAM == "Price" ) { // price code here including all params
>>>> _SECTION_BEGIN( "All Parameters" );
>>>> StaticVarSet( "myControlParam1", ParamColor( "Color",
>>>> colorBlack ) );
>>>> StaticVarSet( "myControlParam2", ParamStyle( "Style" ) );
>>>> StaticVarSet( "myControlParam3", Param( "Fast Periods", 12, 1,
>>>> 100, 1 ) );
>>>> StaticVarSet( "myControlParam4", Param( "Slow Periods", 26, 1,
>>>> 100, 1 ) );
>>>> StaticVarSet( "myControlParam5", Param( "Signal", 9, 1, 100, 1 ) );
>>>> _SECTION_END();
>>>>
>>>> // generic param fetch block
>>>> myControlParam1 = StaticVarGet( "myControlParam1" );
>>>> myControlParam2 = StaticVarGet( "myControlParam2" );
>>>> myControlParam3 = StaticVarGet( "myControlParam3" );
>>>> myControlParam4 = StaticVarGet( "myControlParam4" );
>>>> myControlParam5 = StaticVarGet( "myControlParam5" );
>>>> // all the code to plot the price pane
>>>> Plot( C, "Close", myControlParam1, styleNoTitle | myControlParam2
>>>> | GetPriceStyle() );
>>>> Title = "Price + Params";
>>>> }
>>>>
>>>>
>>>> else if ( IAM == "MACDH" ) { // MACDcode here including all params
>>>>
>>>> // generic param fetch block
>>>> myControlParam1 = StaticVarGet( "myControlParam1" );
>>>> myControlParam2 = StaticVarGet( "myControlParam2" );
>>>> myControlParam3 = StaticVarGet( "myControlParam3" );
>>>> myControlParam4 = StaticVarGet( "myControlParam4" );
>>>> myControlParam5 = StaticVarGet( "myControlParam5" );
>>>> // all the code to plot the MACD pane
>>>> MD1 = MACD( myControlParam3, myControlParam4 );
>>>> MDS = Signal( myControlParam3, myControlParam4, myControlParam5 );
>>>> MDH = MDS - MD1;
>>>> Plot( MDH, "MACD", myControlParam1, styleHistogram | styleNoTitle
>>>> | myControlParam2 );
>>>> Plot( 0 , "MACD", colorBlack );
>>>> Title = "MACD-Histogram";
>>>> }
>>>>
>>>> else if ( IAM == "MACD" ) { // Stoch code here including all params
>>>>
>>>> // generic param fetch block
>>>> myControlParam1 = StaticVarGet( "myControlParam1" );
>>>> myControlParam2 = StaticVarGet( "myControlParam2" );
>>>> myControlParam3 = StaticVarGet( "myControlParam3" );
>>>> myControlParam4 = StaticVarGet( "myControlParam4" );
>>>> myControlParam5 = StaticVarGet( "myControlParam5" );
>>>> // all the code to plot the Stochpane
>>>> MD1 = MACD( myControlParam3, myControlParam4 );
>>>> Plot( MD1, "MACD", myControlParam1, styleNoTitle |
>>>> myControlParam2 );
>>>> Plot( 0 , "MACD", colorBlack );
>>>> Title = "MACD";
>>>> }
>>>>
>>>> else { Title = "Select Pane Function"; }
>>>>
>>>>
>>>> On Oct 13, 2009, at 12:19 PM, bistrader wrote:
>>>>
>>>>> One has to go to each chart to change the parameters for that  
>>>>> chart.
>>>>>
>>>>> The afl is a system so all parameters are needed so that Buy and
>>>>> Sell can be defined. I can, for example, change the Macd  
>>>>> parameters
>>>>> via the top chart but these changes are not reflected in the  
>>>>> middle
>>>>> Macd chart. I have to go to the middle chart, change the Macd
>>>>> parameters and then see the revised Macd chart.
>>>>>
>>>>> I really can not put parameters within each 'if' as I need for the
>>>>> system buys and sells. I guess I will have to live with this.
>>>>>
>>>>> Thanks for the help as understand another way of doing charts.
>>>>>
>>>>> --- In amibroker@xxxxxxxxxxxxxxx
>>> <mailto:amibroker%40yahoogroups.com>, Keith McCombs <kmccombs@>  
>>> wrote:
>>>>>>
>>>>>> Bistrader --
>>>>>> I rarely use Param() --
>>>>>> However, I _believe_ that if the Param() statements are outside  
>>>>>> and
>>>>>> before the plot() statements that they will effect the three  
>>>>>> charts
>>>>>> equally. But if this isn't so, you might explicitly try declaring
>>>>>> the
>>>>>> arrays that you are setting equal to Param() as Global. Again, I
>>>>>> am not
>>>>>> sure. You will have to try it.
>>>>>>
>>>>>> I also _believe_ that, whatever Param() statements you put  
>>>>>> inside the
>>>>>> if(GetChartID()==chartID + 1){ }, will effect that pane only.
>>>>>> -- Keith
>>>>>>
>>>>>> bistrader wrote:
>>>>>>>
>>>>>>>
>>>>>>> Got it and thanks. I will do it now. I am hoping that I can  
>>>>>>> right
>>>>>>> click on first chart, change parameters and see all 3 charts
>>>>>>> change as
>>>>>>> I move parameter bars around.
>>>>>>>
>>>>>>> --- In amibroker@xxxxxxxxxxxxxxx
>>> <mailto:amibroker%40yahoogroups.com> <mailto:amibroker
>>>>>>> %40yahoogroups.com>,
>>>>>>> Keith McCombs <kmccombs@> wrote:
>>>>>>>>
>>>>>>>> Bistrader --
>>>>>>>> Yes you insert link 3 times, once for each chart. You want to  
>>>>>>>> do
>>>>>>>> them
>>>>>>>> consecutively, before doing any other charts for other  
>>>>>>>> strategies,
>>>>>>>> because they are numbered consecutively as they are entered.
>>>>>>>>
>>>>>>>> Oops, for the third chart it should be:
>>>>>>>> if(GetChartID()==chartID + 2){
>>>>>>>> instead of:
>>>>>>>> if(GetChartID()==chartID + 1){
>>>>>>>> That's what I get for using cut and paste.
>>>>>>>>
>>>>>>>> BTW, I embedded an image in my first post. It is not displayed,
>>>>>>>> if you
>>>>>>>> view the posts on the Yahoo groups web site. However, if you  
>>>>>>>> view
>>>>>>>> posts
>>>>>>>> in your own email, it is displayed.
>>>>>>>> -- Keith
>>>>>>>>
>>>>>>>> bistrader wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> I will give it a go. Do I insert link the same afl 3 times?  
>>>>>>>>> Once
>>>>>>>>> to
>>>>>>>>> get xxxx and display price, a second time for Macd and  
>>>>>>>>> finally for
>>>>>>>>> stochastic?
>>>>>>>>>
>>>>>>>>> --- In amibroker@xxxxxxxxxxxxxxx
>>> <mailto:amibroker%40yahoogroups.com>
>>>>>>> <mailto:amibroker%40yahoogroups.com>
>>>>>>> <mailto:amibroker%40yahoogroups.com>,
>>>>>>>>> Keith McCombs <kmccombs@> wrote:
>>>>>>>>>>
>>>>>>>>>> bistrader --
>>>>>>>>>> Looks like you might be trying to take to large a bite out of
>>>>>>>>>> that
>>>>>>>>>> sandwich all at once.
>>>>>>>>>>
>>>>>>>>>> Can you do the following to your satisfaction?
>>>>>>>>>> 1. Plot the price chart with the EMA. Leave the shapes for  
>>>>>>>>>> later.
>>>>>>>>>> 2. Plot the MACD histogram on the same chart. Again, shapes  
>>>>>>>>>> for
>>>>>>> later.
>>>>>>>>>> 3. Plot the Stochastic on the same chart. Again, shapes for
>>>>>>>>>> later.
>>>>>>>>>>
>>>>>>>>>> I gave up trying to do the above long ago. Instead, I have  
>>>>>>>>>> three
>>>>>>>>>> separate charts, displayed horizontally. I use one .afl,  
>>>>>>>>>> with the
>>>>>>>>>> following construct:
>>>>>>>>>>
>>>>>>>>>> ////---- code -----/////
>>>>>>>>>> chartID = xxxx; // get xxxx using 'insert' indicator, not  
>>>>>>>>>> 'Apply'
>>>>>>>>>> indicator.
>>>>>>>>>> // do as many inserts has you want charts, in your case 3.
>>>>>>>>>> if(GetChartID()==chartID){
>>>>>>>>>> _SECTION_BEGIN("Price");
>>>>>>>>>> ; // plot price and emas here with shapes if desired
>>>>>>>>>> _SECTION_END();
>>>>>>>>>> }
>>>>>>>>>> if(GetChartID()==chartID + 1){
>>>>>>>>>> _SECTION_BEGIN("MACD");
>>>>>>>>>> ; // plot MACD here with shapes if desired
>>>>>>>>>> _SECTION_END();
>>>>>>>>>> }
>>>>>>>>>> if(GetChartID()==chartID + 1){
>>>>>>>>>> _SECTION_BEGIN("Stoch");
>>>>>>>>>> ; // plot Stoch here with shapes if desired
>>>>>>>>>> _SECTION_END();
>>>>>>>>>> }
>>>>>>>>>> ////---- end code -----/////
>>>>>>>>>>
>>>>>>>>>> Once you've have that working you can move the size and  
>>>>>>>>>> reorder
>>>>>>>>>> the
>>>>>>>>>> charts by using on screen manual manipulation. Scale, display
>>>>>>>>>> dates,
>>>>>>>>>> etc. independently.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> bistrader wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> I am having problems with Plot statements in one afl that I
>>>>>>> want to
>>>>>>>>>>> plot Price (with EMAs) at the top, Macd histogram in the
>>>>>>> middle and
>>>>>>>>>>> stochastic at the bottom. Each of the 3 has PlotShapes as  
>>>>>>>>>>> well.
>>>>>>>>>>>
>>>>>>>>>>> Here is what I have.
>>>>>>>>>>> 1. I use the following for price with EMAs and with  
>>>>>>>>>>> plotshape
>>>>>>> arrows
>>>>>>>>>>> at top. This works fine:
>>>>>>>>>>> Plot(Close, "Close",colorBlack,styleThick);
>>>>>>>>>>> Plot(ema, "EMA",colorRed,styleThick);
>>>>>>>>>>> OffsetTradeArrow = -25;
>>>>>>>>>>> PlotShapes(ema_buy*shapeUpArrow, colorGreen, 0, Fund,
>>>>>>>>> OffsetTradeArrow);
>>>>>>>>>>> PlotShapes(ema_sell*shapeDownArrow, colorRed, 0, Fund,
>>>>>>>>> OffsetTradeArrow);
>>>>>>>>>>>
>>>>>>>>>>> 2. Then, I move on to Macd histogram where I am having
>>>>>>> problems with
>>>>>>>>>>> Min and Max values to start with and then with how to  
>>>>>>>>>>> overlay
>>>>>>>>>>> its
>>>>>>>>>>> PlotShapes:
>>>>>>>>>>>
>>>>>>>>>
>>>>>>> Plot(MACD_Histo,"MACD_Histo",colorBlack,styleHistogram|
>>>>>>> styleOwnScale,min?,max?);
>>>>>>>>>>> OffsetTradeArrow = -25;
>>>>>>>>>>> PlotShapes(macd_buy*shapeUpArrow, colorGreen, 0, MACD_Histo,
>>>>>>>>>>> OffsetTradeArrow);
>>>>>>>>>>> PlotShapes(macd_sell*shapeDownArrow, colorRed, 0,  
>>>>>>>>>>> MACD_Histo,
>>>>>>>>>>> OffsetTradeArrow);
>>>>>>>>>>>
>>>>>>>>>>> I play around (a lot) using an rsi example posted here but  
>>>>>>>>>>> not
>>>>>>> making
>>>>>>>>>>> any progress. I can get Macd_Histo times 100  
>>>>>>>>>>> (Macd_Histo*100)
>>>>>>> to plot
>>>>>>>>>>> with min at -100 and max at 100/20*100 or 500, but have no
>>>>>>> idea why I
>>>>>>>>>>> had to use -100 for min value. The 100/20*100 is from the  
>>>>>>>>>>> rsi
>>>>>>> example
>>>>>>>>>>> posted here. And, I can not figure out how to get PlotShapes
>>>>>>> for macd
>>>>>>>>>>> to be over this Macd_Hist plot.
>>>>>>>>>>>
>>>>>>>>>>> 3. Then, I move onto Stochastic and can only get this to  
>>>>>>>>>>> plot
>>>>>>> over
>>>>>>>>> the
>>>>>>>>>>> Macd_histo and not below it. So, can not figure out how to  
>>>>>>>>>>> do
>>>>>>>>>>> min
>>>>>>>>>>> value, max value and then plotshapes over this.
>>>>>>>>>>> Plot(StochDSlow," Slow
>>>>>>>>> %D",colorRed,styleThick|styleOwnScale,min?,max?);
>>>>>>>>>>>
>>>>>>>>>>> OffsetTradeArrow = -25;
>>>>>>>>>>> PlotShapes(stoch_buy*shapeUpArrow, colorGreen, 0,  
>>>>>>>>>>> StochDSlow,
>>>>>>>>>>> OffsetTradeArrow);
>>>>>>>>>>> PlotShapes(stoch_sell*shapeDownArrow, colorRed, 0,  
>>>>>>>>>>> StochDSlow,
>>>>>>>>>>> OffsetTradeArrow);
>>>>>>>>>>>
>>>>>>>>>>> Help appreciated. Examples too. Thanks.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>
>>>
>>>
>>
>
>
>
>
> ------------------------------------
>
> **** IMPORTANT PLEASE READ ****
> This group is for the discussion between users only.
> This is *NOT* technical support channel.
>
> TO GET TECHNICAL SUPPORT send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> http://www.amibroker.com/feedback/
> (submissions sent via other channels won't be considered)
>
> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/
>
> Yahoo! Groups Links
>
>
>



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/