2 Arrays

Questions about MultiCharts and user contributed studies.
WarEagle
Posts: 36
Joined: 07 Nov 2006
Has thanked: 7 times

2 Arrays

Postby WarEagle » 28 Aug 2010

Hi,

I am attempting to write some code that will take say the last 10 swing highs, and then filter those highs based on other criteria. Those filtered highs would be the ones i want to use in the indicator. I have an array set up for the initial 10 highs. Does anyone have an example of how I can use them to run through a filter and get what I need?

Just for clarification - the filter would be something like if high < higharray[3] then...keep higharray[3]....

Thanks in advance!

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: 2 Arrays

Postby TJ » 28 Aug 2010

WarEagle wrote:Hi,

I am attempting to write some code that will take say the last 10 swing highs, and then filter those highs based on other criteria. Those filtered highs would be the ones i want to use in the indicator. I have an array set up for the initial 10 highs. Does anyone have an example of how I can use them to run through a filter and get what I need?

Just for clarification - the filter would be something like if high < higharray[3] then...keep higharray[3]....

Thanks in advance!


you need to give more information if you expect any help.
a diagram would help.
a flow chart would be even better.
a snippet of work-in-progress would definitely motivate some responses.

WarEagle
Posts: 36
Joined: 07 Nov 2006
Has thanked: 7 times

Re: 2 Arrays

Postby WarEagle » 28 Aug 2010

TJ wrote:you need to give more information if you expect any help.
a diagram would help.
a flow chart would be even better.
a snippet of work-in-progress would definitely motivate some responses.


Hi TJ, thanks for the response. How about all 3? Not "expecting" help here, just relying on the folks that are so good to lend their expertise such as yourself. I think you know this stuff better than anyone!

Hope the flowchart makes sense. The screenshot is from what the code produces, and i circled the highs i would like to keep and drew Xs on the ones i am not interested in. It seems this should be easier than I am making it....

Code: Select all

Inputs:   LeftStrength(4),
       RightStrength(4);

Variables:    oPivotPrice1(0),
      oPivotBar1(0),
      oPivotPrice2(0),
      oPivotBar2(0);
      
Array:      trendlineArray[10](0),
      secondarray[10](0);

condition1 = Pivot(High,125,LeftStrength,RightStrength,1,1,oPivotPrice1,oPivotBar1)<>-1;
condition2 = pivot(high,125,leftstrength,rightstrength,1,1,oPivotPrice2,oPivotBar2)<>-1;

If condition1 AND (oPivotBar1-RightStrength) = 0 AND Condition2 then
  begin
   if trendlineArray[0] > 0 then
   begin
      tl_delete(trendlinearray[0]);
   end;
   
   For Value2 = 0 to 9
   begin
      trendlineArray[Value2] = trendlineArray[Value2+1];
   end;
   
   For Value3 = 10 downto 1
     begin
        secondarray[value3] = secondarray[value3-1];
     end;

   
  trendlineArray[10] = TL_new(d[oPivotBar2],T[oPivotbar2], H[oPivotbar2],d[oPivotBar1],t[oPivotBar1],H[oPivotBar1]);
  tl_setextright(trendlinearray[10], True);
  text_new(date[oPivotBar2],T[oPivotBar2],oPivotPrice2,numtostr(oPivotPrice2,2));
 
  print(d," ", t,"  ", High, trendlineArray[1], trendlineArray[3], oPivotBar1[1],"  ",oPivotPrice1[1],"  ", oPivotPrice1[0],"  ",value3[3]);
 
end;
Attachments
ArrayFilter.png
ArrayFilter.png (72.47 KiB) Viewed 138 times
Untitleddrawing.png
Untitleddrawing.png (32.69 KiB) Viewed 138 times

User avatar
TJ
Posts: 6521
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: 2 Arrays

Postby TJ » 28 Aug 2010

before I dig into your code, I have a few suggestions:
if you want your studies to evolve into complex analysis,
you must develop good coding habits, starting now!

1. avoid using generic variable names: i.e. condition1, value1, etc.,
give each situation an easily identifiable name, so that when you re-visit your code in 3 months' time, you don't have to scratch your head and spend an hour trying to figure out what variable is doing what function.

2. add lots of comments to the codes.
here's a good example. Anybody reading the code can understand the logic flow.
viewtopic.php?f=5&t=7717

phil
Posts: 47
Joined: 09 May 2007

Re: 2 Arrays

Postby phil » 29 Aug 2010

ANd I would suggest you to check www.Markplex.com I think you can inpired yourself by is programation and idea and tutorial.

phil

WarEagle
Posts: 36
Joined: 07 Nov 2006
Has thanked: 7 times

Re: 2 Arrays

Postby WarEagle » 30 Aug 2010

TJ and phil, great suggestions, both. Thanks for the tips. I can see the advantage of commenting code.


Return to “MultiCharts”