How integrate price array in code

Could you help me ?
I need to make that specific strategy will be activated only around specific price array.

Let's take for example some default strategy :

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies
{
   public class TwoBarBreakout_Revisited : WealthScript
   {
      protected override void Execute()
      {
         for(int bar = 60; bar < Bars.Count; bar++)
         {
            if (!IsLastPositionActive)
            {
               // Set-up
               if( Bars.Low[bar] < Bars.Low[bar-1] )
                  if( Bars.High[bar] < Bars.High[bar-1] )
                     if( Bars.Close[bar] < Bars.Open[bar] )
               // Trade filter
               if( SMA.Series( Bars.Close, 5 )[bar] > SMA.Series( Bars.Close, 50 )[bar] )
                  // Entry
                  BuyAtStop( bar+1, Bars.High[bar] + 0.1 * ATR.Series( Bars,2 )[bar] );
            }
            else
            {
               // Added profit taking
               if( !SellAtLimit( bar+1, LastPosition, Bars.High[bar] + 0.5 * ATR.Series( Bars, 2 )[bar], "Take Profit" ) )
                  SellAtTrailingStop( bar+1, LastPosition, Lowest.Series( Low, 2 )[bar], "Trailing Stop" );

            }
         }
      }
   }
}

Open in new window


Where should I put price array in my code ?

I guess it should be looks something like this :


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies
{
   public class TwoBarBreakout_Revisited : WealthScript
   {
               price_array == [ 1.11 ; 2.22; 3.33; 4.44; 5.55; 6.66; 7.77 ; 8.88; 9.99 ]  // MY PRICE ARRAY                  THAT I WANT TO IMPLEMENT how should I do think correctly 

      protected override void Execute()
      {
         for(int bar = 60; bar < Bars.Count; bar++)
         {
            if (!IsLastPositionActive)
            {
               // Set-up
               if( Bars.Low[bar] < Bars.Low[bar-1] )
                  if( Bars.High[bar] < Bars.High[bar-1] )
                     if( Bars.Close[bar] < Bars.Open[bar] )
               // Trade filter
               if( SMA.Series( Bars.Close, 5 )[bar] > SMA.Series( Bars.Close, 50 )[bar] )

                                            If Bars.Close[bar]  >  price_array (//  on 0.12$ ) and Bars.Close[bar]  <  price_array (// on 0.05$)   //  than make some action // I don't know how to integrate condition related to 0.12 and 0.05 cents please take a look on the picture in attachment 


                           
                  // Entry
                  BuyAtStop( bar+1, Bars.High[bar] + 0.1 * ATR.Series( Bars,2 )[bar] );
            }
            else
            {
               // Added profit taking
               if( !SellAtLimit( bar+1, LastPosition, Bars.High[bar] + 0.5 * ATR.Series( Bars, 2 )[bar], "Take Profit" ) )
                  SellAtTrailingStop( bar+1, LastPosition, Lowest.Series( Low, 2 )[bar], "Trailing Stop" );

            }
         }
      }
   }
}

Open in new window


A little bit more clarification

Let say
Price of "A" change from 3.5$ to 2.01$

I would like that before price of "A" reaches 3.33$ ( let say above 12 cents so it will be 3.45$) my algorithm start to check price action on needed to me condition in order to find point of opening potions. In addition, I would like that my algorithm turn off after 5 cents ( 3.28$) when pivot price point is pasted. Moreover, I would like again that my algorithm turn on when price action approach 2.22$ ( again 12cent above = 2.34$ ) and turn off 5 cents below 2.22$ ( 2.17$ )


price_array == [ 1.11 ; 2.22; 3.33; 4.44; 5.55; 6.66; 7.77 ; 8.88; 9.99 ]

So, price array for strategy just another one "if than condition". Please, could you tell me how would be code looks like ?
price-array.png
SunnyXAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
are the Wealthlab modules freely available.. is the documentation available.. This is a specialized area and not using a default system configuration
0
SunnyXAuthor Commented:
yes, it is. There is free 30 days trial and documentation available.
0
SunnyXAuthor Commented:
This is the solution :

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies
{
   public class TwoBarBreakout_Revisited : WealthScript
   {
      public static double GetHighest(double[] dArray)
      {
         double high = double.MinValue;
         
         foreach (double i in dArray) {
            if (i > high)
               high = i;
         }
         
         return high;
      }
      
      public static double GetLowest(double[] dArray)
      {
         double low = double.MaxValue;
         
         foreach (double i in dArray) {
            if (i < low)
               low = i;
         }
         
         return low;
      }
      
      protected override void Execute()
      {
         double[] price_array = new double[]{ 1.11, 2.22, 3.33 };
         double lowest = GetLowest(price_array); double lowEnd = lowest + 0.12;
         double highest = GetHighest(price_array); double hiEnd = highest - 0.12;
         
         ATR atr = ATR.Series( Bars, 2 );
         
         for(int bar = GetTradingLoopStartBar(50); bar < Bars.Count; bar++)
         {
            if (IsLastPositionActive)
            {
               Position p = LastPosition;
               // Added profit taking
               if( !SellAtTrailingStop( bar+1, p, Lowest.Series( Low, 2 )[bar], "Trailing Stop" ) )
                  SellAtLimit( bar+1, p, High[bar] + 0.5 * atr[bar], "Take Profit" );
            }
            else
            {
               // Set-up
               if( Low[bar] < Low[bar-1] )
                  if( High[bar] < High[bar-1] )
                     if( Close[bar] < Open[bar] )
                        // Trade filter
                        if( SMA.Series( Close, 5 )[bar] > SMA.Series( Close, 50 )[bar] )
                        {
                           //Array filter
                           double price = Close[bar];
                           bool isPriceWithinRange = (price > lowest && price < lowEnd) || (price > hiEnd && price < highest);
                           
                           // Entry
                           if( isPriceWithinRange )
                              BuyAtStop( bar+1, High[bar] + 0.1 * atr[bar] );
                        }
            }
         }
      }
   }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SunnyXAuthor Commented:
Nobody answer on my question in this forum so I figure out by myself
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.