Link to home
Start Free TrialLog in
Avatar of SunnyX
SunnyX

asked on

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
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

are the Wealthlab modules freely available.. is the documentation available.. This is a specialized area and not using a default system configuration
Avatar of SunnyX
SunnyX

ASKER

yes, it is. There is free 30 days trial and documentation available.
ASKER CERTIFIED SOLUTION
Avatar of SunnyX
SunnyX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SunnyX

ASKER

Nobody answer on my question in this forum so I figure out by myself