I think in C# the math would be something like this:
public static void Main (string[] args) {
// Input the starting number
Console.Write("Enter the starting number: ");
int number = Convert.ToInt32(Console.ReadLine());
// First 10s place above
int first10sPlaceAbove = (int)Math.Ceiling((double)number / 10) * 10;
// First 10s place below
int first10sPlaceBelow = (int)Math.Floor((double)number / 10) * 10;
Console.WriteLine("First 10s place above: " + first10sPlaceAbove);
Console.WriteLine("First 10s place below: " + first10sPlaceBelow);
}
But for ninjascript I want the starting number to be the opening price and I want the printed lines to be long and short positions. Any help is appreciated, thanks
Would it be like this:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] == 0)
{
// Get the opening price of the current bar
openingPrice = Bars.GetOpen(0);
// Calculate the first 10s place above and below the opening price
int first10sPlaceAbove = (int)Math.Ceiling(openingPrice / 10) * 10;
int first10sPlaceBelow = (int)Math.Floor(openingPrice / 10) * 10;
// Check if we have already placed orders
if (!Position.MarketPosition.HasAnyPosition)
{
// Place a sell order (short position) if the price crosses above the first 10s place
if (Close[0] > first10sPlaceAbove)
{
EnterShort();
}
// Place a buy order (long position) if the price crosses below the first 10s place
else if (Close[0] < first10sPlaceBelow)
{
EnterLong();
}
}
}
}
Comment