ScrewTurn

Active Trader Strategies API Community ChartStyles Community Commissions Community Components Community Indicators Community Providers Community Visualizers Knowledge Base Misc Optimizers PosSizers Standard Indicators TASC Traders Tips TASCIndicators Tutorial Videos
RSS

Navigation







Quick Search
»
Advanced Search »

PoweredBy

Syntax


public static bool AlmostEquals(double double1, double double2, double precision)

Parameter Description

double1 First double value
double2 Second double value
precision Desirable precision when comparing

Description

Sometimes there's a need to compare two values of type double to determine whether they are within a close approximation to each other. The following function taken from Stackoverflow will handle it.

Example

Example below compares two double values for approximate equality within one tick value of an instrument.

Note: since the function is marked as static, you don't have to create an instance of the Calculate class that contains it:


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

namespace WealthLab.Strategies { using c = Community.Components.Calculate; public class AlmostEqualsDemo : WealthScript { protected override void Execute() { double tick = Bars.SymbolInfo.Tick; SetBarColors( Color.Silver, Color.Silver ); for(int bar = 1; bar < Bars.Count; bar++) { bool result = ( c.AlmostEquals(Close[bar],Low[bar],tick) || c.AlmostEquals(Close[bar],Low[bar]+tick,tick) || c.AlmostEquals(Open[bar],Low[bar],tick) || c.AlmostEquals(Open[bar],Low[bar]+tick,tick) ); if( result ) SetBarColor( bar, Color.Magenta ); } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes.

Used under license from FMR Corp. Copyright 2008 FMR Corp. All rights reserved.


ScrewTurn Wiki version 3.0.2.509. Some of the icons created by FamFamFam.